Open ulrichard opened 2 years ago
This sounds like a bug in cc
- it should be building as C++ not C.
Hi @ulrichard, are you still hitting this issue?
Hi I'm getting this issue when compliling to wasm:
error: failed to run custom build command for `bitcoinconsensus v0.20.2-0.5.0`
Caused by:
process didn't exit successfully: `/home/sebastian/vsc-workspace/coinstr-wasm/target/debug/build/bitcoinconsensus-3fe2c1af365d97c8/build-script-build` (exit status: 1)
--- stdout
OPT_LEVEL = Some("0")
TARGET = Some("wasm32-unknown-unknown")
HOST = Some("x86_64-unknown-linux-gnu")
cargo:rerun-if-env-changed=CXX_wasm32-unknown-unknown
CXX_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=CXX_wasm32_unknown_unknown
CXX_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_CXX
TARGET_CXX = None
cargo:rerun-if-env-changed=CXX
CXX = None
cargo:rerun-if-env-changed=CXXFLAGS_wasm32-unknown-unknown
CXXFLAGS_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=CXXFLAGS_wasm32_unknown_unknown
CXXFLAGS_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_CXXFLAGS
TARGET_CXXFLAGS = None
cargo:rerun-if-env-changed=CXXFLAGS
CXXFLAGS = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
cargo:rerun-if-env-changed=CXX_wasm32-unknown-unknown
CXX_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=CXX_wasm32_unknown_unknown
CXX_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_CXX
TARGET_CXX = None
cargo:rerun-if-env-changed=CXX
CXX = None
cargo:rerun-if-env-changed=CXXFLAGS_wasm32-unknown-unknown
CXXFLAGS_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=CXXFLAGS_wasm32_unknown_unknown
CXXFLAGS_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_CXXFLAGS
TARGET_CXXFLAGS = None
cargo:rerun-if-env-changed=CXXFLAGS
CXXFLAGS = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
running: "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "depend/bitcoin/src" "-I" "depend/bitcoin/src/secp256k1/include" "-I" "depend/bitcoin/src/secp256k1" "-Wall" "-Wextra" "-std=c++11" "-Wno-unused-parameter" "-D__STDC_FORMAT_MACROS" "-DSECP256K1_BUILD=1" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DENABLE_MODULE_RECOVERY=1" "-DUSE_FIELD_10X26=1" "-DUSE_SCALAR_8X32=1" "-o" "/home/sebastian/vsc-workspace/coinstr-wasm/target/wasm32-unknown-unknown/debug/build/bitcoinconsensus-e49a0edf6d52a536/out/depend/bitcoin/src/secp256k1/src/secp256k1.o" "-c" "depend/bitcoin/src/secp256k1/src/secp256k1.c"
cargo:warning=error: invalid argument '-std=c++11' not allowed with 'C'
exit status: 1
--- stderr
error occurred: Command "clang" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "depend/bitcoin/src" "-I" "depend/bitcoin/src/secp256k1/include" "-I" "depend/bitcoin/src/secp256k1" "-Wall" "-Wextra" "-std=c++11" "-Wno-unused-parameter" "-D__STDC_FORMAT_MACROS" "-DSECP256K1_BUILD=1" "-DUSE_NUM_NONE=1" "-DUSE_FIELD_INV_BUILTIN=1" "-DUSE_SCALAR_INV_BUILTIN=1" "-DENABLE_MODULE_RECOVERY=1" "-DUSE_FIELD_10X26=1" "-DUSE_SCALAR_8X32=1" "-o" "/home/sebastian/vsc-workspace/coinstr-wasm/target/wasm32-unknown-unknown/debug/build/bitcoinconsensus-e49a0edf6d52a536/out/depend/bitcoin/src/secp256k1/src/secp256k1.o" "-c" "depend/bitcoin/src/secp256k1/src/secp256k1.c" with args "clang" did not execute successfully (status code exit status: 1).
Do you know what might be the cause?
@ulrichard did you manage to solve your issue?
I still get the same error as above with the current master. It is not important to me TBH. It would have been cool to integrate it in a website, but not essential for me. I guess that's easier with pure rust stuff.
Note that in general you cannot safely link most C code with wasm_bindegn. While we should fix this, you'll need to use a different wasm build target to make it work.
I am getting the same error with wasm-pack build --release --target web
.
warning: error: invalid argument '-std=c++11' not allowed with 'C'
error: failed to run custom build command for `bitcoinconsensus v0.20.2-0.5.0`
@TheBlueMatt Could you elaborate? Is there a way to make this library work with wasm-pack build
?
I started experimenting: https://github.com/AminaBank/rust-bitcoinconsensus/tree/feature/wasm But so far, it doesn't look too good.
I had a brief look and I rekon that the problem is the secp build, which requires various things like patching out functions etc. I'd say we have to port all the wasm build stuff from secp256k1
to this repo. At a very minimum.
I wonder if we can patch out libsecp entirely and link against the one in rust-secp-sys. We would like to do this anyway to minimize the amount of code we compile.
I'm confused why we think this is related to secp - the specific error (passing a C++ argument when building targeting C) sounds like either we're invoking cc
wrong (which I doubt, cause it works for non-wasm) or cc
is buggy building C++ for wasm, which needs to be fixed in the cc
crate.
I'm confused why we think this is related to secp
By "related to secp" I meant I messed around with the build file and could not get secp to build, and that is the first step before building the C++ code.
I got past the exact error in this issue.
Ah, so somehow we shouldn't be passing the std=c++...
argument in the secp builds? I assume we'll just hit this error eventually once we get to C++ files though.
Adding this to C++ builds and not to C builds seems to fix this specific error.
config.cpp(true)
EDIT: I am not totally confident in this statement.
What is the reason that compiling for wasm in rust-secp256k1 is patching the Cargo.toml file just for the test? Would that modification break anything else if applied permanently? I don't think in this state, it could be used as a direct dependency.
@ulrichard it wouldn't hurt anything but it would be wasteful. We need to build rust-secp as both a dylib and a cdylib for WASM but we don't need any special handling for non-WASM users. (I'm actually unsure if we need this at all ... the git history shows this line being introduced in April 2020 into travis.yml and we've just preserved it since then.)
I don't think in this state, it could be used as a direct dependency.
Is this a philosophical claim or a technical one? Because many people do use rust-secp as a direct dependency, including WASM users.
@apoelstra Can you point me to a project, where rust-secp is used as a dependency for building wasm? I'm fairly new to wasm, and that could help a lot seeing how it can be done.
I'm guessing mutiny uses wasm, is that right @benthecarman?
Yes
Ok, I dug a bit deeper. The issue with rust-secp seems solvable.
But then the C++ files use the C++ std lib. This seems to be forbidden for wasm32-unknown-unknown and hence wasm-pack.
There might be a way for wasm32-unknown-emscripten or wasm32-wasi but I am not sure about that yet.
Sweet, nice one! This might be in the process of getting solved upstream: https://github.com/bitcoin-core/secp256k1/pull/1461. For the immediate fix we can do the whole WASM dance that we do in rust-secp256k1
. A better solution IMO would be working out how to get rust-bitcoinconsensus
and rust-secp256k1
to play together so we don't have to duplicate this work in both places.
Jumping to the thread here, I have the same problem when introducing bitcoinconsensus
feature here
https://github.com/lightningdevkit/ldk-node/pull/301/files#diff-2e9d962a08321605940b5a657135052fbcef87b5e360662bb527c96d9a615542R62
the CI is not happy when building kotlin-android bindings https://github.com/lightningdevkit/ldk-node/actions/runs/9287478277/job/25556603253?pr=301.
Thanks @jbesraa, FWIW I don't personally have any ideas or spare clock cycles to do anything about this ATM.
no worries @tcharding. I am trying to work on this, will report back.