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 compile clipper-sys to WASM on Mac M1 #26

Open
caewok opened this issue Mar 21, 2022 · 4 comments
Open

Cannot compile clipper-sys to WASM on Mac M1 #26

caewok opened this issue Mar 21, 2022 · 4 comments

Comments

@caewok
Copy link

caewok commented Mar 21, 2022

I am trying to compile some basic clipper functions to WASM, to use as a bridge to Javascript. This is on a Mac M1, which might have something to do with the issue I am seeing.

(FYI, I have compiled various other Rust code and crates to WASM without issue on this same M1 computer, so I think I have the basics down. Just not sure how to address this compiler error.)

When using the default Mac clang compiler, I get this error:

[INFO]: 🌀 Compiling to Wasm...
Compiling clipper-sys v0.7.2
The following warnings were emitted during compilation:

warning: In file included from clipper/clipper.cpp:41:
warning: clipper/clipper.hpp:52:10: fatal error: 'vector' file not found
warning: #include
warning: ^~~~~~~~
warning: 1 error generated.

error: failed to run custom build command for clipper-sys v0.7.2

Caused by:
process didn't exit successfully: /Users/rhead/git/fvtt-test-ccw/intersections/target/release/build/clipper-sys-6c959c9fe2b70968/build-script-build (exit status: 1)
--- stdout
cargo:rerun-if-changed=clipper
TARGET = Some("wasm32-unknown-unknown")
HOST = Some("aarch64-apple-darwin")
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = None
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-o" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/clipper/clipper.o" "-c" "clipper/clipper.cpp"
cargo:warning=In file included from clipper/clipper.cpp:41:
cargo:warning=clipper/clipper.hpp:52:10: fatal error: 'vector' file not found
cargo:warning=#include
cargo:warning= ^~~~~~~~
cargo:warning=1 error generated.
exit status: 1

--- stderr

error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-o" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/clipper/clipper.o" "-c" "clipper/clipper.cpp" with args "clang" did not execute successfully (status code exit status: 1).

Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute cargo build: exited with exit status: 101
full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

I would guess that clang is trying to compile "clipper/clipper.hpp" as a c file, not a c++ file. But if so, I don't know why, and don't know how to fix it.

I also tried installing gcc in homebrew, and then forced it to use that compiler instead, i.e, by passing environmental variables to the compile script: CC=/opt/homebrew/bin/gcc-11 CXX=/opt/homebrew/bin/g++-11 ./build_wasm.sh
I still get a compile error, albeit a different one:

[INFO]: 🌀 Compiling to Wasm...
Compiling clipper-sys v0.7.2
error: failed to run custom build command for clipper-sys v0.7.2

Caused by:
process didn't exit successfully: /Users/rhead/git/fvtt-test-ccw/intersections/target/release/build/clipper-sys-6c959c9fe2b70968/build-script-build (exit status: 101)
--- stdout
cargo:rerun-if-changed=clipper
TARGET = Some("wasm32-unknown-unknown")
HOST = Some("aarch64-apple-darwin")
CXX_wasm32-unknown-unknown = None
CXX_wasm32_unknown_unknown = None
TARGET_CXX = None
CXX = Some("/opt/homebrew/bin/g++-11")
CXXFLAGS_wasm32-unknown-unknown = None
CXXFLAGS_wasm32_unknown_unknown = None
TARGET_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = None
running: "/opt/homebrew/bin/g++-11" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/clipper/clipper.o" "-c" "clipper/clipper.cpp"
exit status: 0
running: "/opt/homebrew/bin/g++-11" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/clipper/wrapper.o" "-c" "clipper/wrapper.cpp"
exit status: 0
AR_wasm32-unknown-unknown = None
AR_wasm32_unknown_unknown = None
TARGET_AR = None
AR = None
CROSS_COMPILE = None
running: "ar" "cq" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/libclipper.a" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/clipper/clipper.o" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/clipper/wrapper.o"
exit status: 0
running: "ar" "s" "/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out/libclipper.a"
exit status: 0
cargo:rustc-link-lib=static=clipper
cargo:rustc-link-search=native=/Users/rhead/git/fvtt-test-ccw/intersections/target/wasm32-unknown-unknown/release/build/clipper-sys-527f62cc4ff17778/out
CXXSTDLIB_wasm32-unknown-unknown = None
CXXSTDLIB_wasm32_unknown_unknown = None
TARGET_CXXSTDLIB = None
CXXSTDLIB = None
cargo:rustc-link-lib=stdc++

--- stderr
thread 'main' panicked at 'not implemented: target_os: unknown, target_env: ', /Users/rhead/.cargo/registry/src/github.com-1ecc6299db9ec823/clipper-sys-0.7.2/build.rs:23:14
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute cargo build: exited with exit status: 101
full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

Any insights would be much appreciated! Thanks!

@dizeeee
Copy link

dizeeee commented Oct 4, 2022

I get a similar issue when trying to build on Linux (x86_64). This doesn't seem to be architecture specific.

@jhalfsharp
Copy link

I get a similar issue on Windows 11 ("x86_64-pc-windows-msvc").

@lelongg
Copy link
Owner

lelongg commented Feb 13, 2023

I cannot easily reproduce this as the CI is building but I merged the fix from #27 and it seems related. Can you try master and see if it fix your issue ?

@CodedNil
Copy link

CodedNil commented Feb 14, 2024

I am still getting this issue on the master branch on windows and linux compiling for WASM, project built using trunk

cargo:warning=clipper/clipper.hpp:52:10: fatal error: 'vector' file not found

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

5 participants