briansmith / ring

Safe, fast, small crypto using Rust
Other
3.73k stars 703 forks source link

Error compiling on `aarch64-pc-windows-msvc` #1461

Closed tmpfs closed 1 year ago

tmpfs commented 2 years ago

Hi,

Thanks for the library, I am having trouble compiling ring:0.16.20 on Windows (I don't usually use windows so this is all very new to me).

I have followed the instructions in BUILDING.md and I think I have installed all the right libraries (VSCode 2022 with the C++ Development workflow and MSVC v142 - VS 2019 C++ ARM64 build tools) but it is quite likely I am missing something.

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

Caused by:
  process didn't exit successfully: `Y:\git\desktop\target\debug\build\ring-26b79f943f484e4c\build-script-build` (exit code: 101)
  --- stdout
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-pc-windows-msvc")
  HOST = Some("x86_64-pc-windows-msvc")
  CC_aarch64-pc-windows-msvc = None
  CC_aarch64_pc_windows_msvc = None
  TARGET_CC = None
  CC = None
  CFLAGS_aarch64-pc-windows-msvc = None
  CFLAGS_aarch64_pc_windows_msvc = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = None
  DEBUG = Some("true")
  montgomery.c
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(191): error C2065: 'BN_ULLONG': undeclared identifier
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(191): error C2146: syntax error: missing ';' before identifier 'result'
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(191): warning C4555: result of expression not used
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(191): error C2065: 'result': undeclared identifier
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(191): error C2146: syntax error: missing ';' before identifier 'a'
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(191): warning C4552: '*': result of expression not used
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(192): error C2065: 'result': undeclared identifier
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(193): error C2065: 'result': undeclared identifier
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\internal.h(193): warning C4293: '>>': shift count negative or too big, undefined behavior
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(38): warning C4163: '_addcarry_u64': not available as an intrinsic function
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(38): warning C4163: '_subborrow_u64': not available as an intrinsic function
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(62): warning C4013: '_addcarry_u64' undefined; assuming extern returning int
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(62): warning C4242: '=': conversion from 'int' to 'Carry', possible loss of data
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(76): warning C4242: '=': conversion from 'int' to 'Carry', possible loss of data
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(92): warning C4013: '_subborrow_u64' undefined; assuming extern returning int
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(92): warning C4242: '=': conversion from 'int' to 'Carry', possible loss of data
  C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\crypto\fipsmodule\bn\../../limbs/limbs.inl(106): warning C4242: '=': conversion from 'int' to 'Carry', possible loss of data

  --- stderr
  running "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX64\\arm64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "include" "-W4" "/GS" "/Gy" "/EHsc" "/GR-" "/Zc:wchar_t" "/Zc:forScope" "/Zc:inline" "/Zc:rvalueCast" "/sdl" "/Wall" "/wd4127" "/wd4464" "/wd4514" "/wd4710" "/wd4711" "/wd4820" "/wd5045" "/Od" "/RTCsu" "-DNDEBUG" "-c" "/FoY:\\git\\desktop\\target\\aarch64-pc-windows-msvc\\debug\\build\\ring-9fa65205694170bf\\out\\montgomery.obj" "crypto/fipsmodule/bn/montgomery.c"
  thread 'main' panicked at 'execution failed', C:\Users\muji\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\build.rs:656:9

I am note sure why rust thinks the host is x86_64 (HOST = Some("x86_64-pc-windows-msvc")) when I check the architecture:

wmic os get OSArchitecture

I get:

OSArchitecture
ARM 64-bit Processor

FYI, I am running Windows 11 on an M1 via Parallels but I don't know if that is relevant.

Any pointers would be much appreciated 🙏

RevenantBob commented 2 years ago

Running into the same issues.

RevenantBob commented 2 years ago

Alright, this was partially a matter of RTFM for me.

Documentations shows you need to set TARGET_CC for cross compile, it also says it uses clang. So it should be worth noting you need clang-cl as your TARGET_CC to cross compile.

However...

There is a bug in the build.rs for 16.20 that causes the compile to fail anyway. This is fixed in the 0.17.0-alpha.11.

Of course, it's alpha... hopefully a full 0.17 will be released.

briansmith commented 1 year ago

Thanks! I am going to close this since it seems to be resolved. I'm hoping to make the cross-compiling "just work" in the near future.

elichai commented 6 months ago

Trying to cross compile to aarch64-pc-windows-msvc with clang-cl fails the build.rs of ring with this error:

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

Caused by:
  process didn't exit successfully: `/target/debug/build/ring-24946b25ae0d9fc1/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_8_
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-pc-windows-msvc")
  HOST = Some("aarch64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-pc-windows-msvc
  CC_aarch64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CC_aarch64_pc_windows_msvc
  CC_aarch64_pc_windows_msvc = Some("/usr/lib/llvm-18/bin/clang-cl")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-pc-windows-msvc
  CFLAGS_aarch64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_pc_windows_msvc
  CFLAGS_aarch64_pc_windows_msvc = Some("-fuse-ld=lld /winsysroot /home/docker/msvc")

  --- stderr
  running "clang" "-O0" "--target=aarch64-pc-windows-msvc" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "--target=aarch64-pc-windows-msvc" "-fuse-ld=lld" "/winsysroot" "/home/docker/msvc" "-I" "include" "-I" "/target/aarch64-pc-windows-msvc/debug/build/ring-094b8bdf4cbf5b2b/out" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-g3" "-DNDEBUG" "-c" "-o/target/aarch64-pc-windows-msvc/debug/build/ring-094b8bdf4cbf5b2b/out/aesv8-armx-win64.o" "/home/docker/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/pregenerated/aesv8-armx-win64.S"
  clang: error: no such file or directory: '/winsysroot'
  clang: warning: /home/docker/msvc: 'linker' input unused [-Wunused-command-line-argument]
  thread 'main' panicked at /home/docker/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/build.rs:670:9:
  execution failed
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
drl990114 commented 4 months ago

Trying to cross compile to aarch64-pc-windows-msvc with clang-cl fails the build.rs of ring with this error:

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

Caused by:
  process didn't exit successfully: `/target/debug/build/ring-24946b25ae0d9fc1/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_8_
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-pc-windows-msvc")
  HOST = Some("aarch64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-pc-windows-msvc
  CC_aarch64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CC_aarch64_pc_windows_msvc
  CC_aarch64_pc_windows_msvc = Some("/usr/lib/llvm-18/bin/clang-cl")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-pc-windows-msvc
  CFLAGS_aarch64-pc-windows-msvc = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_pc_windows_msvc
  CFLAGS_aarch64_pc_windows_msvc = Some("-fuse-ld=lld /winsysroot /home/docker/msvc")

  --- stderr
  running "clang" "-O0" "--target=aarch64-pc-windows-msvc" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "--target=aarch64-pc-windows-msvc" "-fuse-ld=lld" "/winsysroot" "/home/docker/msvc" "-I" "include" "-I" "/target/aarch64-pc-windows-msvc/debug/build/ring-094b8bdf4cbf5b2b/out" "-fvisibility=hidden" "-std=c1x" "-Wall" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-g3" "-DNDEBUG" "-c" "-o/target/aarch64-pc-windows-msvc/debug/build/ring-094b8bdf4cbf5b2b/out/aesv8-armx-win64.o" "/home/docker/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/pregenerated/aesv8-armx-win64.S"
  clang: error: no such file or directory: '/winsysroot'
  clang: warning: /home/docker/msvc: 'linker' input unused [-Wunused-command-line-argument]
  thread 'main' panicked at /home/docker/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/build.rs:670:9:
  execution failed
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

@elichai Have you solved this problem? I also encountered the same problem.

briansmith commented 4 months ago

Instead of using clang-cl, just use clang.