mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.06k stars 122 forks source link

Unable to Build WebAssembly #2289

Closed Mousaka closed 10 months ago

Mousaka commented 10 months ago

Problem

I'm following the readme on how to build this project with web assembly but I've been stuck on an error for a while. I'm suspecting it might have to do with the fact that I'm on an Apple M1 processor but I'm not sure. I'm very unfamiliar with these tools and can't really figure out how to fix the error. This is my output when trying to build

scryer-prolog git:(master) βœ— wasm-pack build --target web -- --no-default-features
[INFO]: 🎯  Checking for the Wasm target...
[INFO]: πŸŒ€  Compiling to Wasm...
   Compiling ring v0.17.7
The following warnings were emitted during compilation:

warning: ring@0.17.7: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
warning: ring@0.17.7: 1 error generated.

error: failed to run custom build command for `ring v0.17.7`

Caused by:
  process didn't exit successfully: `/Users/kristianlundstrom/prog/prolog/scryer-prolog/target/release/build/ring-694d0fc977e27e24/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("3")
  TARGET = Some("wasm32-unknown-unknown")
  HOST = Some("x86_64-apple-darwin")
  cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown
  CC_wasm32-unknown-unknown = None
  cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown
  CC_wasm32_unknown_unknown = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown
  CFLAGS_wasm32-unknown-unknown = None
  cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown
  CFLAGS_wasm32_unknown_unknown = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "include" "-I" "/Users/kristianlundstrom/prog/prolog/scryer-prolog/target/wasm32-unknown-unknown/release/build/ring-8fc08209dfe85ffb/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-nostdlibinc" "-DNDEBUG" "-DRING_CORE_NOSTDLIBINC=1" "-o" "/Users/kristianlundstrom/prog/prolog/scryer-prolog/target/wasm32-unknown-unknown/release/build/ring-8fc08209dfe85ffb/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"
  cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'

  cargo:warning=1 error generated.

  exit status: 1

  --- stderr

  error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "include" "-I" "/Users/kristianlundstrom/prog/prolog/scryer-prolog/target/wasm32-unknown-unknown/release/build/ring-8fc08209dfe85ffb/out" "-Wall" "-Wextra" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-nostdlibinc" "-DNDEBUG" "-DRING_CORE_NOSTDLIBINC=1" "-o" "/Users/kristianlundstrom/prog/prolog/scryer-prolog/target/wasm32-unknown-unknown/release/build/ring-8fc08209dfe85ffb/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c" with args "clang" did not execute successfully (status code exit status: 1).

Error: Compiling your crate to WebAssembly failed
Caused by: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit status: 101
  full command: cd "/Users/kristianlundstrom/prog/prolog/scryer-prolog" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown" "--no-default-features"

Questions

  1. Is this only happening for me or did something break in a recent release?
  2. Does anyone have any tips of things to try in order to fix this?
  3. Does anyone know what the problem might be?

Cheers!

bakaq commented 10 months ago

I think the problem is that you didn't install the wasm32-unknown-unknown toolchain, as is said on the error:

'No available targets are compatible with triple "wasm32-unknown-unknown"'

If you are using rustup, you can install it with this command:

$ rustup target add wasm32-unknown-unknown

This is needed to be able to compile Rust to Wasm.

Mousaka commented 10 months ago

Thank you for answering @bakaq !

Unfortunately I did that already but I forgot to mention it. It's the only concrete thing I found while googling but it's still not working.

$ rustup target list | grep wasm32-unknown-unknown
wasm32-unknown-unknown (installed)

~Let me know if you know anything I could try.~

EDIT: Found this guide that includes some special steps for MacOS and by following them it worked! https://learn.sapio-lang.org/ch01-01-installation.html#local-quickstart

It might be something with Apple's own Clang version that is not working properly (someone thought so here https://github.com/sapio-lang/sapio/issues/161#issuecomment-999425210) but I'm not sure.

Mousaka commented 10 months ago

Problem solved by installing wasm-pack by following these special instructions for macOS image from https://learn.sapio-lang.org/ch01-01-installation.html#local-quickstart