koute / cargo-web

A Cargo subcommand for the client-side Web
Apache License 2.0
1.1k stars 80 forks source link

Linker error during debug `cargo build` on 0.6.22, `cargo web build` succeeds #165

Open sdobz opened 5 years ago

sdobz commented 5 years ago

Hello koute, I've been following your progress on the new js macro closely, thanks for getting debug builds working! Well, maybe.

I'm using the yew library and recently it started having a linker error during cargo build. My intuition points to the issue being in this project as it has the most drastic recent changes, and cargo web build finishes without error, though I will happily cross post this if relevant.

Platform: Windows Subsystem for Linux (ubuntu)

Tooling Versions:

rustup show:
stable-x86_64-unknown-linux-gnu (default)
rustc 1.31.0 (abe02cefd 2018-12-04)

cargo web --version: cargo-web 0.6.22

Here is a minimum repository to reproduce the problem (a mini-pro-repro-repo) : https://github.com/sdobz/cargo-web-yew-linker-issue

Here is a truncated cargo build output (full output in the readme above):

       Fresh unicode-xid v0.1.0
       <TRUNC>
       Fresh yew v0.5.0 (https://github.com/DenisKolodin/yew#8c4ba179)
   Compiling cargo-web-problem v0.1.0 (/mnt/c/Users/vince/Projects/cargo-web-problem)
     Running `rustc --edition=2018 --crate-name cargo_web_problem src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=e3d07a1c168769ac -C
extra-filename=-e3d07a1c168769ac --out-dir /mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps -C incremental=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/incremental -L dependency=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps --extern yew=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/libyew-c1a76617db60700f.rlib -L native=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/build/backtrace-sys-1b1df7c21cb65ef2/out`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/vkhougaz/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/cargo_web_problem-e3d07a1c168769ac.180ki2rplwge5olv.rcgu.o" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/cargo_web_problem-e3d07a1c168769ac.191mt35y1bjuajmv.rcgu.o" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/cargo_web_problem-e3d07a1c168769ac.1alfuf7m4yb41jzz.rcgu.o" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/cargo_web_problem-e3d07a1c168769ac.1fmlxknqsv31yagd.rcgu.o" <TRUNC> "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps" "-L" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/build/backtrace-sys-1b1df7c21cb65ef2/out" "-L" "/home/vkhougaz/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/libyew-c1a76617db60700f.rlib" <TRUNC> "-Wl,-Bdynamic" "-lutil" "-lutil" "-ldl" "-lrt" "-lpthread" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
  = note: /mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/libyew-c1a76617db60700f.rlib(yew-c1a76617db60700f.yew.chdglymg-cgu.4.rcgu.o): In function `_$LT$yew..virtual_dom..vtag..VTag$LT$COMP$GT$$GT$::apply_diffs::snippet::__cargo_web_snippet_0da47658267a7497de743e1b0892f992ba6ca6ef::h3c0be4116e3d9a90':
          /home/vkhougaz/.cargo/git/checkouts/yew-cffb4df3674cc4fb/8c4ba17/<::stdweb::webcore::macros::_js_impl macros>:30: undefined reference to `emscripten_asm_const_int'
          <TRUNC>
          /mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/libstdweb-4ef46cc31103a766.rlib(stdweb-4ef46cc31103a766.stdweb.9xsep76m-cgu.4.rcgu.o): In function `stdweb::webapi::node::INode::remove_child::snippet::__cargo_web_snippet_b06dde4acf09433b5190a4b001259fe5d4abcbc2::h3d346f1ad921de02':
          /home/vkhougaz/.cargo/registry/src/github.com-1ecc6299db9ec823/stdweb-0.4.11/src/webcore/macros.rs:101: undefined reference to `emscripten_asm_const_int'
          /mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/libstdweb-4ef46cc31103a766.rlib(stdweb-4ef46cc31103a766.stdweb.9xsep76m-cgu.4.rcgu.o):/home/vkhougaz/.cargo/registry/src/github.com-1ecc6299db9ec823/stdweb-0.4.11/src/webcore/macros.rs:101: more undefined references to `emscripten_asm_const_int' follow
          collect2: error: ld returned 1 exit status

error: aborting due to previous error

error: Could not compile `cargo-web-problem`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name cargo_web_problem
src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=e3d07a1c168769ac -C extra-filename=-e3d07a1c168769ac --out-dir /mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps -C incremental=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/incremental -L dependency=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps --extern yew=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/deps/libyew-c1a76617db60700f.rlib -L native=/mnt/c/Users/vince/Projects/cargo-web-problem/target/debug/build/backtrace-sys-1b1df7c21cb65ef2/out` (exit code: 1)
koute commented 5 years ago

It is normal that cargo build doesn't work. (: You should always use cargo web build to build your project.

If you execute cargo build then cargo will build your project using whatever the default target it is configured with, which in your case is x86_64-unknown-linux-gnu. This doesn't really make any sense as both stdweb and yew are Web frameworks, and x86_64-unknown-linux-gnu is a native, non-Web target. stdweb only supports asmjs-unknown-emscripten, wasm32-unknown-emscripten and wasm32-unknown-unknown as targets.

Why are you using cargo build anyway? If I know your use case I might be able to help you better.

krysopath commented 3 years ago

Hello kind people!

I wanted to build a function that validates javascript, which is part of a post body. However, the target I am building this for is not a web build. That service MUST support validating a reduced set of javascript instructions, before processing them.

Obviously an insecure thing I am working with here, ..

my questions:

I thought that there must be macro to create javascript code in rust. Like the macro that constructs html in yew e.g. And so I am looking here :)