rustpq / pqcrypto

Rust Post-Quantum cryptography
212 stars 38 forks source link

Build issue on ARM macOS #38

Closed rozbb closed 2 years ago

rozbb commented 2 years ago

I'm not quite sure how to diagnose this. cargo test builds everything, and almost everything succeeds. The only erroring build I'm getting is the following

  cargo:rustc-link-lib=static=kyber512-90s_clean
  cargo:rustc-link-search=native=/Users/micro/projects/pqcrypto-compat/target/debug/build/pqcrypto-kyber-ab7d6f1520cab3df/out
  TARGET = Some("aarch64-apple-darwin")
  HOST = Some("aarch64-apple-darwin")
  AR_aarch64-apple-darwin = None
  AR_aarch64_apple_darwin = None
  HOST_AR = None
  AR = None
  running: "ar" "s" "/Users/micro/projects/pqcrypto-compat/target/debug/build/pqcrypto-kyber-ab7d6f1520cab3df/out/libkyber512-90s_aarch64.a"
  cargo:warning=error: /Library/Developer/CommandLineTools/usr/bin/ranlib: can't open file: /Users/micro/projects/pqcrypto-compat/target/debug/build/pqcrypto-kyber-ab7d6f1520cab3df/out/libkyber512-90s_aarch64.a (No such file or directory)
  cargo:warning=/Library/Developer/CommandLineTools/usr/bin/ar: internal ranlib command failed
  exit status: 1

I can do more tests on my mac if you need more info

thomwiggers commented 2 years ago

Hi, can you try just building the native libraries (so in this case crypto_kem/kyber512-90s/aarch64) in PQClean?

rozbb commented 2 years ago

Got it. The bug was simpler than expected: there simply is no kyber512-90s/aarch64 to speak of!

There's only clean and avx2 impls. So something in the build script is not checking whether the target exists.

thomwiggers commented 2 years ago

Ah, right! The code isn't detected but we have a Yaml file that keeps track of all the available implementations for which we need to generate code. Clearly I accidentally claimed support for Aarch64 for Kyber-90s, even though there was no implementation.

(If you need it, there's probably a reasonable way to patch the Kyber-aarch64 code in PQClean to use the 90s crypto and we would merge that PR)

rjzak commented 1 year ago

This issue seems to be unresolved, as I'm getting similar errors on freshly checkout code.

The following warnings were emitted during compilation:

warning: error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: can't open file: /Users/rjzak/Documents/Projects/Profian/pqcrypto/target/debug/build/pqcrypto-kyber-a38dc4006de060ee/out/libkyber512_clean.a (No such file or directory)
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar: internal ranlib command failed

error: failed to run custom build command for `pqcrypto-kyber v0.7.6 (/Users/rjzak/Documents/Projects/Profian/pqcrypto/pqcrypto-kyber)`

Caused by:
  process didn't exit successfully: `/Users/rjzak/Documents/Projects/Profian/pqcrypto/target/debug/build/pqcrypto-kyber-2c033184f04cff93/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("aarch64-apple-darwin")
  HOST = Some("aarch64-apple-darwin")
  AR_aarch64-apple-darwin = None
  AR_aarch64_apple_darwin = None
  HOST_AR = None
  AR = None
  running: "ar" "s" "/Users/rjzak/Documents/Projects/Profian/pqcrypto/target/debug/build/pqcrypto-kyber-a38dc4006de060ee/out/libkyber512_clean.a"
  cargo:warning=error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: can't open file: /Users/rjzak/Documents/Projects/Profian/pqcrypto/target/debug/build/pqcrypto-kyber-a38dc4006de060ee/out/libkyber512_clean.a (No such file or directory)
  cargo:warning=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar: internal ranlib command failed
  exit status: 1

  --- stderr

  error occurred: Command "ar" "s" "/Users/rjzak/Documents/Projects/Profian/pqcrypto/target/debug/build/pqcrypto-kyber-a38dc4006de060ee/out/libkyber512_clean.a" with args "ar" did not execute successfully (status code exit status: 1).

Looks like a .a file should be been created but wasn't, but I don't know what code was run to try to compile something.

rjzak commented 1 year ago

Seems to work, I had forgotten about the submodules (git submodule update --init).

I am confused though, as pgcrypto-kyber is a dependency of wasi-crypto, and wasi-crypto is a dependency of Wasmtime when compiling with cargo build --features wasi-crypto. Yet for some reason, it (compiling Wasmtime with Wasi-Crypto) works on Linux but fails on macOS with an error similar to one above. Maybe cargo isn't checking out the submodule used by a dependency as it should? But would it work on one OS but not the other?

thomwiggers commented 1 year ago

Okay there's not exactly enough information to go on here, and I don't really know how WASI works. I'm also afraid that I have time to get in to that I'm afraid.

However, if you or anyone else does manage to figure out what's going on with your problem there, I'm very welcoming to contributions that make the crates more reliable.