rustwasm / book

The Rust and WebAssembly Book
https://rustwasm.github.io/docs/book/
MIT License
1.73k stars 208 forks source link

Hello World not working because cfg_if is missing in Cargo.toml #200

Open dd-pardal opened 4 years ago

dd-pardal commented 4 years ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Follow the tutorial until this section;
  2. Build the project using wasm-pack build, as instructed;
  3. See the error.

Expected behavior Successful compilation, with no errors.

Screenshots Not really a screenshot, but here's the output from wasm-pack:

PS D:\fakepath> wasm-pack.exe build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling wasm-game-of-life v0.1.0 (D:\fakepath)
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
 --> src\lib.rs:1:1
  |
1 | extern crate cfg_if;
  | ^^^^^^^^^^^^^^^^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/27812

error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
 --> src\lib.rs:6:5
  |
  |     ^^^^^^^^^^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/27812

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.

To learn more, run the command again with --verbose.
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101

Additional context This can be solved by simply adding cfg-if = "0.1.10" to the [dependencies] table in Cargo.toml.

Bcpoole commented 4 years ago

The wasm-pack-template removed the need for this dependency and 7f570329fb4db36bf9418d90666600468b7a2bb8 updated the src code, though the web book hasn't been updated.