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

Building rust-openssl to wasm32 on MacOS fails #1613

Closed
alex-coinfund opened this issue Mar 18, 2022 · 9 comments
Closed

Building rust-openssl to wasm32 on MacOS fails #1613

alex-coinfund opened this issue Mar 18, 2022 · 9 comments

Comments

@alex-coinfund
Copy link

Reposting from rust-lang/rust#95057 just in case anyone in the openssl community encountered something similar.

I am working on project that uses openssl and compiles to wasm (wasm32-unknown-emscripten toolchain). It builds on Linux just fine, but when I try building it on my MacOS Big Sur, I get the following error (removing some irrelevant information from the output):

error: failed to run custom build command for `openssl-sys v0.9.72`

Caused by:
  process didn't exit successfully: `/Users/alex/projects/mufl-poc-cpp/src/external/nitroattest/aws-nitroattest/target/debug/build/openssl-sys-c48c44c33a472711/build-script-main` (exit status: 101)
  --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=WASM32_UNKNOWN_EMSCRIPTEN_OPENSSL_NO_VENDOR
  WASM32_UNKNOWN_EMSCRIPTEN_OPENSSL_NO_VENDOR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_VENDOR
  OPENSSL_NO_VENDOR unset
  CC_wasm32-unknown-emscripten = None
  CC_wasm32_unknown_emscripten = None
  TARGET_CC = None
  CC = None
  CFLAGS_wasm32-unknown-emscripten = None
  CFLAGS_wasm32_unknown_emscripten = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  running "perl" "./Configure" "--prefix=/Users/alex/projects/mufl-poc-cpp/src/external/nitroattest/aws-nitroattest/target/wasm32-unknown-emscripten/debug/build/openssl-sys-85f599ecbb1dcfeb/out/openssl-build/install" "no-dso" "no-shared" "no-ssl3" "no-unit-test" "no-comp" "no-zlib" "no-zlib-dynamic" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-D__STDC_NO_ATOMICS__"
  Configuring OpenSSL version 1.1.1n (0x101010efL) for gcc
  Using os-specific seed configuration
  Creating configdata.pm
  Creating Makefile

[SNIP]

  --- stderr
  ar: creating archive apps/libapps.a
  warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: apps/libapps.a the table of contents is empty (no object file members in the library define global symbols)
  ar: creating archive libcrypto.a
  warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: libcrypto.a the table of contents is empty (no object file members in the library define global symbols)
  ar: creating archive libssl.a
  warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: libssl.a the table of contents is empty (no object file members in the library define global symbols)
  LLVM ERROR: malformed uleb128, extends past end
  /bin/sh: line 1: 64526 Abort trap: 6           ranlib "/Users/alex/projects/mufl-poc-cpp/src/external/nitroattest/aws-nitroattest/target/wasm32-unknown-emscripten/debug/build/openssl-sys-85f599ecbb1dcfeb/out/openssl-build/install/lib/$fn.new"
  make: *** [install_dev] Error 134
  thread 'main' panicked at '


  Error installing OpenSSL:
      Command: "make" "install_dev"
      Exit status: exit status: 2

Obviously, it is incorrectly using Apple's native libraries and tools where it should be using those provided by emscripten. My workaround was to link emscripten's llvm-ar as ar (same for ranlib) and put them temporarily on the front of my $PATH, which works. Yet, I still wanted to report, or see if I'm missing something obvious wrt building wasm on MacOS.

@yihuang
Copy link

yihuang commented Apr 11, 2022

#1016

@Skepfyr
Copy link
Collaborator

Skepfyr commented Jan 5, 2023

@alex-coinfund I'm surprised it compiled fine on Linux! A bunch of discussion about getting OpenSSL working on WASM is happening in #1016, I suspect they'd appreciate a description of how you got it working on Linux.

@alex-coinfund
Copy link
Author

This was a while back, I don’t remember off-hand. Maybe @shakhvit remembers?

@shakhvit
Copy link

shakhvit commented Jan 5, 2023

@Skepfyr
As @yihuang suggested in #1016 I've added vendored feature to my cargo.toml.
Also, I am using wasm32-unknown-emsrcipten target, while in #1016 wasm32-unknown-unknown and wasm32-wasi are mainly discussed. Hope it will help.

@johnkeates
Copy link

For some reason it doesn't build on Linux or Darwin at all for me, regardless of which with llvm and native vs. packaged libraries and tools I configure. Did you add any other specific changes to make it wasm compatible?

@shakhvit
Copy link

shakhvit commented Feb 8, 2023

@johnkeates I've created a repository with an example configuration. Please take a look at the build instructions in README.md and if you have any questions please feel free to contact me.

But I am not using anything specific. Just as I said vendored feature and wasm32-unknown-emscripten target.

Here is the link to the repo:
https://github.com/shakhvit/rust_openssl_wasm_build

@johnkeates
Copy link

johnkeates commented Feb 8, 2023

@shakhvit Thanks! I'll try it out in a clean environment. I just noticed that there is a slight difference in our targets as I'm using wasm32-unknown-unknown so that might be the culprit and maybe my defect doesn't belong in this issue after all ✂️

Update: this totally works for emscripten, so that's a nice improvement, it means that technically the wasm32 or a wasi SDK could do the same if there was an environment injector available. I did spot someone talking about this yesterday but I can't find the comment right now. It looks like WASI support in generally is getting plenty of traction so this would likely just be a matter of time to get a more easy-to-find implementation.

@johnkeates
Copy link

Turns out that wasi as a target now works so this also works 😎

@Skepfyr
Copy link
Collaborator

Skepfyr commented Mar 12, 2023

Given everything above I'm going to claim this works now, feel free to reopen if that's not true.

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