rustwasm.github.io icon indicating copy to clipboard operation
rustwasm.github.io copied to clipboard

Using `cargo generate` as described in the game of life example not working

Open bravecorvus opened this issue 6 years ago • 12 comments

Describe the Bug

I was following the example code at https://rustwasm.github.io/docs/book/game-of-life/setup.html.

I was able to install cargo install cargo-generate without a problem, and also have the latest LTS version of NPM. (Also, did a rustup update this morning to update my stable installation of rustc and cargo.)

However, when I run cargo generate --git https://www.github.com/rustwasm/wasm-pack-template and name my project wasm-game-of-life, it fails to clone with the error â›” Git Error: failed to clone into: /Users/andrewlee/Documents/Projects/Personal/Rust/wasm-game-of-life4g21l6

Steps to Reproduce

  1. cargo install cargo-generate
  2. cargo generate --git https://www.github.com/rustwasm/wasm-pack-template
  3. Name project

If applicable, add a link to a test case (as a zip file or link to a repository we can clone).

Expected Behavior

Not sure but I assume it should have set up a nice webasm project for me.

Actual Behavior

â›” Git Error: failed to clone into: /Users/andrewlee/Documents/Projects/Personal/Rust/wasm-game-of-life4g21l6

If applicable, add screenshots to help explain your problem.

img

Additional Context

OS: macOS 10.14.5 cargo version: cargo 1.35.0 (6f3e9c367 2019-04-04) rustc version: rustc 1.35.0 (3c235d560 2019-05-20) npm version: 6.4.1 node version: v10.15.3 git version: git version 2.21.0

bravecorvus avatar May 26 '19 16:05 bravecorvus

This seems like a bug in cargo-generate. cc @ashleygwilliams

fitzgen avatar Jun 03 '19 18:06 fitzgen

Did you have network access? Was there any other output afterwards?

fitzgen avatar Jun 03 '19 18:06 fitzgen

I do.

I tried again right now, and i got a slightly different error

img

bravecorvus avatar Jun 03 '19 22:06 bravecorvus

Ya think this could be related to this?

bravecorvus avatar Jun 03 '19 22:06 bravecorvus

hrm. will have to investigate- having just released another CLI tool that leverages this under the hood and having tested it extensively on multiple platforms with a gallery of templates- i'm not entirely sure what could cause this bug! my expectation is that it is likely associated with our use of libgit2...but i'll have to look into it. thank you so much for filing and sorry you are running into this!

ashleygwilliams avatar Jun 04 '19 00:06 ashleygwilliams

Thanks @ashleygwilliams . I really enjoyed watching the talk you did in Kyiv, Ukraine in April of 2017. And thanks @fitzgen for the initial response. Yall keep up the good work.

bravecorvus avatar Jun 04 '19 04:06 bravecorvus

I am seeing the same problem, or is it a different one?

The Travis CI rules installed with the game of life tutorial template tell it to use cargo-generate version 0.2. However that version can not be used any longer as liquid v0.15.0 doesn't compile due to an accepted regression in Rust, see https://github.com/rust-lang/rust/issues/60958

I tried to change the rules to use cargo-generate version 0.4, but that leads to a failure later when cargo-generate is actually being run:

$ cargo generate --git . --name testing Creating project called testing... Git Error: failed to find branch master The command "cargo generate --git . --name testing" exited with 0.

svenfoo avatar Sep 11 '19 20:09 svenfoo

Hi, is this still being looked into?

@ashleygwilliams ,

Sorry, just wanted to bring this to your attention.

@RiderSargent,

I've found someone who created a docker image with the environment set up. I struggled to try to build it myself out of masochism, but his seems to be relatively stable as a workaround (hopefully temporarily)

https://users.rust-lang.org/t/tutorial-conways-game-of-life-in-rust-and-webassembly/16823

Kelvinm avatar Jun 15 '20 19:06 Kelvinm

I'm also still getting this error (@gilgameshskytrooper's original issue).

Are there any workarounds? Perhaps regarding absolute/relative paths or something?

Did you ever get this working @gilgameshskytrooper?

It looks like it is tagging six alphanumeric chars onto the end of the path it's trying to clone into, but they seem to be new random chars every time:

Screenshot 2020-06-19 at 10 35 13

Please let me know if there's any further info that could help.

Thanks!

My setup: OS: macOS 10.15.5 Cargo version: cargo 1.44.0 (05d080faa 2020-05-06) rustc version: rustc 1.44.0 (49cae5576 2020-06-01) npm version: 6.14.4 node version: v12.18.0 git version: git version 2.24.3 (Apple Git-128) (hub version 2.14.2)

RiderSargent avatar Jun 19 '20 09:06 RiderSargent

@RiderSargent I have not. Sorry. But I haven't tried for quite some time so I'm not sure if this is still an issue.

bravecorvus avatar Jun 19 '20 12:06 bravecorvus

Hello, for context, it's working for me for the non-www URL. My setup:

  • macOS 10.14.6
  • cargo 1.46.0-nightly (089cbb80b 2020-06-15)
  • rustc 1.46.0-nightly (6bb3dbfc6 2020-06-22)
  • npm version 6.11.3
  • node version 12.4.0
  • git version 2.23.0

I did a bit of digging:

  1. cargo-generate calls git::create which is returning an error result here

  2. git::create uses GitRemote to checkout the project here

  3. That's coming from cargo::sources. Here's the GitRemote::checkout function

  4. There's a format_error proc that's building the error message here

The console output from @RiderSargent's screenshot shows "failed to clone", so we know the operation argument is "clone".

  1. There's a call to fetch that calls format_error with "clone" here

  2. fetch is defined in the same file here

That's as far as I got. It looks like something is failing in that fetch function, but I don't know what. There are references to git2 and the "command-line" git in the function so maybe check if upgrading libgit helps.

Perhaps it would be possible to create a minimal example that calls that function directly - or to checkout the cargo project and point cargo-generate to it in Cargo.toml and trace it through with some println! statements.

As a workaround in the short-term, perhaps you can avoid cargo-generate for now and clone the repository manually. You'd have to replace the interpolations manually (e.g. {{author}}). I don't know how difficult that would be. Alternatively, if you just want a barebones wasm project, I have an example project here: https://github.com/tuzz/minimal-rust-wasm

tuzz avatar Jun 23 '20 11:06 tuzz

I had this issue. Fixed with workarounds described here: https://github.com/ashleygwilliams/cargo-generate/issues/168

workaround: remove url rewrites from your ~/.gitconfig

ezpuzz avatar Aug 28 '20 00:08 ezpuzz