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

Is it possible to compile a rust project which uses ada-url to WASM? #15

Closed
chanced opened this issue Jun 28, 2023 · 8 comments
Closed
Labels
question Further information is requested

Comments

@chanced
Copy link
Contributor

chanced commented Jun 28, 2023

First off, thanks for the awesome crate. Also, I apologize for creating an issue for a question.

I'm wondering if it is possible to use ada-url in a project when compiling to WASM? I've experimented with it and haven't had much luck. At the same time, I have no experience with WASM so I'm hoping that I am missing something.

For context, I'm building a JSON Schema crate. At some point in the future, I'd like to compile it to WASM. While I'd really like to use ada-url, I also do not want to pick up a dependency that makes a WASM target impractical.

Thank you for your time. Again, I'm sorry this is somewhat off topic. Please feel free to close if you'd prefer to keep issues to... well, issues.

@anonrig
Copy link
Member

anonrig commented Jun 28, 2023

We compile and test Ada core to WebAssembly - https://github.com/ada-url/ada/tree/main/tests/wasm. I think it is possible to compile Ada Rust package to WASM, but if you encountered a specific issue, we'll be happy to help.

@anonrig anonrig added the question Further information is requested label Jun 28, 2023
@anonrig
Copy link
Member

anonrig commented Jun 28, 2023

cc @Boshen cc @Brooooooklyn

@Boshen
Copy link
Collaborator

Boshen commented Jun 28, 2023

Quick first attempt:

Compile to wasm error output
rust  main ❯ rustup target add wasm32-unknown-unknown

info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
info: installing component 'rust-std' for 'wasm32-unknown-unknown'
rust  main ❯ cargo build --target wasm32-unknown-unknown
  Downloaded proc-macro2 v1.0.58
  Downloaded syn v2.0.16
  Downloaded link_args v0.6.0
  Downloaded 3 crates (291.3 KB) in 2.11s
   Compiling proc-macro2 v1.0.58
   Compiling libc v0.2.144
   Compiling unicode-ident v1.0.8
   Compiling quote v1.0.27
   Compiling link_args v0.6.0
   Compiling thiserror v1.0.40
   Compiling jobserver v0.1.26
   Compiling cc v1.0.79
   Compiling syn v2.0.16
   Compiling ada-url v1.0.3 (/Users/boshen/github/rust)
   Compiling thiserror-impl v1.0.40
The following warnings were emitted during compilation:

warning: In file included from ./deps/ada.cpp:3:
warning: ./deps/ada.h:20:10: fatal error: 'string' file not found
warning: #include <string>
warning:          ^~~~~~~~
warning: 1 error generated.

error: failed to run custom build command for `ada-url v1.0.3 (/Users/boshen/github/rust)`

Caused by:
  process didn't exit successfully: `/Users/boshen/github/rust/target/debug/build/ada-url-bba85f8f0ceb130d/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=deps/ada.cpp
  cargo:rerun-if-changed=deps/ada.h
  cargo:rerun-if-changed=deps/ada_c.h
  TARGET = Some("wasm32-unknown-unknown")
  OPT_LEVEL = Some("0")
  HOST = Some("aarch64-apple-darwin")
  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")
  running: "clang++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "./deps/ada.h" "-I" "./deps/ada_c.h" "-Wall" "-Wextra" "-std=c++17" "-o" "/Users/boshen/github/rust/target/wasm32-unknown-unknown/debug/build/ada-url-26ed0d01891e2d46/out/./deps/ada.o" "-c" "./deps/ada.cpp"
  cargo:warning=In file included from ./deps/ada.cpp:3:
  cargo:warning=./deps/ada.h:20:10: fatal error: 'string' file not found
  cargo:warning=#include <string>
  cargo:warning=         ^~~~~~~~
  cargo:warning=1 error generated.
  exit status: 1

  --- stderr


  error occurred: Command "clang++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-unknown" "-I" "./deps/ada.h" "-I" "./deps/ada_c.h" "-Wall" "-Wextra" "-std=c++17" "-o" "/Users/boshen/github/rust/target/wasm32-unknown-unknown/debug/build/ada-url-26ed0d01891e2d46/out/./deps/ada.o" "-c" "./deps/ada.cpp" with args "clang++" did not execute successfully (status code exit status: 1).

@lemire
Copy link
Member

lemire commented Jun 28, 2023

@Boshen Make sure your build settings include a reference to the C++ standard library.

rust-lang/rust-bindgen#1834

@Boshen
Copy link
Collaborator

Boshen commented Jun 29, 2023

@anonrig Can you try the commands on your machine, I'm not familiar with the settings.

rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown

@chanced
Copy link
Contributor Author

chanced commented Jun 29, 2023

I had asked about this on the unofficial rust discord channel before posting here. It seems that including header files at least gets it to compile.

https://discord.com/channels/273534239310479360/1123415399770374164

@Brooooooklyn
Copy link
Collaborator

From I know, the C++ can't be compiled into wasm32-unknown-unknown target

@chanced
Copy link
Contributor Author

chanced commented Jul 10, 2023

Sorry for the delayed response, I was on vacation.

I'll go ahead and close this. Thank you for all of your help!

@chanced chanced closed this as completed Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants