Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build on NixOS #1

Open
ThibaultLemaire opened this issue Dec 28, 2019 · 6 comments
Open

Cannot build on NixOS #1

ThibaultLemaire opened this issue Dec 28, 2019 · 6 comments

Comments

@ThibaultLemaire
Copy link

ThibaultLemaire commented Dec 28, 2019

So after figuring out some dependencies, I managed to get the compilation up to this step.

error: linking with `emcc` failed: exit code: 1
...
CRITICAL:root:Could not verify LLVM version: [Errno 2] No such file or directory
CRITICAL:root:fastcomp in use, but LLVM has not been built with the JavaScript backend as a target, llc reports:
===========================================================================
(no targets could be identified: [Errno 2] No such file or directory)
===========================================================================
CRITICAL:root:you can fall back to the older (pre-fastcomp) compiler core, although that is not recommended, see http://kripken.github.io/emscripten-site/docs/building_from_source/LLVM-Backend.html
INFO:root:(Emscripten: Running sanity checks)
ERROR:root:failing sanity checks due to previous fastcomp failure

I figured I was missing fastcomp (whatever that is), so I added the emscriptenfastcomp package to my environment. Except now stb_image fails to build with

error: failed to run custom build command for `stb_image v0.2.2`

--- stdout
TARGET = Some("wasm32-unknown-emscripten")
OPT_LEVEL = Some("0")
TARGET = Some("wasm32-unknown-emscripten")
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("wasm32-unknown-emscripten")
TARGET = Some("wasm32-unknown-emscripten")
HOST = Some("x86_64-unknown-linux-gnu")
CC_wasm32-unknown-emscripten = None
CC_wasm32_unknown_emscripten = None
TARGET_CC = Some("clang")
TARGET = Some("wasm32-unknown-emscripten")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_wasm32-unknown-emscripten = None
CFLAGS_wasm32_unknown_emscripten = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("true")
running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "--target=wasm32-unknown-emscripten" "-Wall" "-Wextra" "-o" "/home/naughtylus/dev/rust-sdl2-wasm/target/wasm32-unknown-emscripten/debug/build/stb_image-4e5f119215957d84/out/src/stb_image.o" "-c" "src/stb_image.c"
cargo:warning=error: unknown target triple 'wasm32-unknown-emscripten', please use -triple or -arch
exit code: 1

--- stderr
thread 'main' panicked at '

Internal error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "--target=wasm32-unknown-emscripten" "-Wall" "-Wextra" "-o" "/home/naughtylus/dev/rust-sdl2-wasm/target/wasm32-unknown-emscripten/debug/build/stb_image-4e5f119215957d84/out/src/stb_image.o" "-c" "src/stb_image.c" with args "clang" did not execute successfully (status code exit code: 1).

So I'm not sure if that's progress or not, and I don't know where to go from there.

@tanis2000
Copy link
Owner

I didn’t even know there was an OS called NixOS until today :)

Looking at the error it seems that the wasm32-unknown-emacripten triple isn’t recognized by the version of LLVM in use on your system.

Do you actually have that triple installed through rustup?

@ThibaultLemaire
Copy link
Author

Yes rustup target list shows

...
wasm32-unknown-emscripten (installed)
...

The Nix package manager has it's own way of handling package installation and dependencies.
I'm using it to create development environments with only the required libraries for building each project.

I'm still trying to figure out the exact dependencies of your example. I know there's at least:

  • rustup
  • python
  • nodejs
  • unzip

But I'm still unsure if cargo-web requires emscripten installed on the system or if it rolls its own, in which case my installing emscriptenfastcomp is shadowing cargo-web's clang and that might explain the target not found.

(I've also tried to add LLVM and binaryen to the environment without success)

Can you successfully compile the project without cargo-web? As with cargo build --target=wasm32-unknown-emscripten ? If so, trying to at least get that working might be easier for me.

@tanis2000
Copy link
Owner

AFAIK cargo-web downloads a version of emscripten on its own, but you should be able to override that.

I can’t remember if this project does work with just cargo.

I’m on holiday at the moment and I do not have access to a computer. I’ll have a look at it when I get back home in the first week of January.

You can try to find a way of making cargo-web use your own emscripten and llcm and that would probably solve this issue

@ThibaultLemaire
Copy link
Author

After further investigation, I've opened an issue on cargo-web : koute/cargo-web#230

It looks like this issue is not tied to your work and this example project: I can't compile anything with cargo-web and the emscripten target.

@tanis2000
Copy link
Owner

Now that’s interestIng. Please keep me posted.

@ThibaultLemaire
Copy link
Author

ThibaultLemaire commented Jan 11, 2020

Okay so as mentioned on the linked issue, with the correct version of rust, I can compile against my system emscripten.

Here's what works for me:

❯ cargo --version
cargo 1.39.0 (1c6ec66d5 2019-09-30)

❯ cargo web start --use-system-emscripten
    Finished dev [unoptimized + debuginfo] target(s) in 0.70s

If you need to serve any extra files put them in the 'static' directory
in the root of your crate; they will be served alongside your application.
You can also put a 'static' directory in your 'src' directory.

Your application is being served at '/main.js'. It will be automatically
rebuilt if you make any changes in your code.

You can access the web server at `http://[::1]:8000`.

Although now I'm having issues with the result (I'll open a new issue My Firefox doesn't support WebGL anymore since a recent update apparently).

edit: Tried it on an other machine, it's working fine.

On a side note, would you like me to contribute my shell.nix file? Basically it just brings rustup and emscripten into scope and adds $HOME/.cargo/bin to the path so that the cargo-web bin is discoverable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants