ring icon indicating copy to clipboard operation
ring copied to clipboard

Ring does not cross compile from linux to x86_64-pc-windows-gnu

Open rustrial opened this issue 4 years ago • 6 comments

Ring does not cross compile from linux to x86_64-pc-windows-gnu (using mingw64 toolchain). I guess we need to differentiate between native compilation and cross compilation in build.rs.

cross build --target x86_64-pc-windows-gnu
   Compiling ring v0.17.0-not-released-yet (/project)
error: failed to run custom build command for `ring v0.17.0-not-released-yet (/project)`

Caused by:
  process didn't exit successfully: `/target/debug/build/ring-076d38a9c102f180/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_0_not_released_yet_
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE
  cargo:rerun-if-env-changed=PERL_EXECUTABLE

  --- stderr
  running "perl" "crypto/chacha/asm/chacha-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/chacha-x86_64-nasm.asm"
  running "perl" "crypto/fipsmodule/aes/asm/aesni-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/aesni-x86_64-nasm.asm"
  running "perl" "crypto/fipsmodule/aes/asm/vpaes-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/vpaes-x86_64-nasm.asm"
  running "perl" "crypto/fipsmodule/bn/asm/x86_64-mont.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/x86_64-mont-nasm.asm"
  running "perl" "crypto/fipsmodule/bn/asm/x86_64-mont5.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/x86_64-mont5-nasm.asm"
  running "perl" "crypto/fipsmodule/ec/asm/p256-x86_64-asm.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/p256-x86_64-asm-nasm.asm"
  running "perl" "crypto/fipsmodule/modes/asm/aesni-gcm-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/aesni-gcm-x86_64-nasm.asm"
  running "perl" "crypto/fipsmodule/modes/asm/ghash-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/ghash-x86_64-nasm.asm"
  running "perl" "crypto/fipsmodule/sha/asm/sha512-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/sha512-x86_64-nasm.asm"
  running "perl" "crypto/cipher_extra/asm/chacha20_poly1305_x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/chacha20_poly1305_x86_64-nasm.asm"
  running "perl" "crypto/fipsmodule/sha/asm/sha512-x86_64.pl" "nasm" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/sha256-x86_64-nasm.asm"
  running "./target/tools/windows/nasm/nasm" "-o" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/chacha-x86_64-nasm.o" "-f" "win64" "-i" "include/" "-i" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/" "-Xgnu" "-gcv8" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/chacha-x86_64-nasm.asm"
  thread 'main' panicked at 'failed to execute ["./target/tools/windows/nasm/nasm" "-o" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/chacha-x86_64-nasm.o" "-f" "win64" "-i" "include/" "-i" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/" "-Xgnu" "-gcv8" "/target/x86_64-pc-windows-gnu/debug/build/ring-0a349917f970412e/out/chacha-x86_64-nasm.asm"]: No such file or directory (os error 2)', build.rs:711:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

rustrial avatar Aug 20 '21 10:08 rustrial

@rustrial Are you building ring from a release published on crates.io? It seems like you are not, since you are running perl and nasm. Releases published on crates.io have those steps done specifically to enable better cross-compilation and to otherwise make building easier.

briansmith avatar Aug 25 '21 20:08 briansmith

If you insist on building from a Git checkout then you'd need to install nasm, which is available for Linux.

briansmith avatar Aug 25 '21 20:08 briansmith

@briansmith Even if I use a published release from crates.io I get an error. So for example if I try to cross compile one of my cli tools which (transitively) depends on ring I get below error.

cross build --target x86_64-pc-windows-gnu
...
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/target/debug/build/ring-9cbc6d0e55a2caad/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("0")
  TARGET = Some("x86_64-pc-windows-gnu")
  HOST = Some("x86_64-unknown-linux-gnu")
  CC_x86_64-pc-windows-gnu = None
  CC_x86_64_pc_windows_gnu = Some("x86_64-w64-mingw32-gcc-posix")
  CFLAGS_x86_64-pc-windows-gnu = None
  CFLAGS_x86_64_pc_windows_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  running "x86_64-w64-mingw32-gcc-posix" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "include" "-Wall" "-Wextra" "-std=c1x" "-Wbad-function-cast" "-Wnested-externs" "-Wstrict-prototypes" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-g3" "-DNDEBUG" "-c" "-o/target/x86_64-pc-windows-gnu/debug/build/ring-dbc92c538f9e8de1/out/aes_nohw.o" "crypto/fipsmodule/aes/aes_nohw.c"
  In file included from /usr/share/mingw-w64/include/crtdefs.h:10:0,
                   from /usr/share/mingw-w64/include/stddef.h:7,
                   from include/GFp/base.h:65,
                   from include/GFp/aes.h:52,
                   from crypto/fipsmodule/aes/aes_nohw.c:15:
  /usr/share/mingw-w64/include/_mingw.h:236:6: warning: "__clang_major__" is not defined, evaluates to 0 [-Wundef]
   #if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) && \
        ^~~~~~~~~~~~~~~
  /usr/share/mingw-w64/include/_mingw.h:236:30: warning: "__clang_major__" is not defined, evaluates to 0 [-Wundef]
   #if (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1)) && \
                                ^~~~~~~~~~~~~~~
  In file included from /usr/share/mingw-w64/include/crtdefs.h:10:0,
                   from /usr/share/mingw-w64/include/stddef.h:7,
                   from include/GFp/base.h:65,
                   from include/GFp/aes.h:52,
                   from crypto/fipsmodule/aes/aes_nohw.c:15:
  /usr/share/mingw-w64/include/_mingw.h:406:66: warning: "__cplusplus" is not defined, evaluates to 0 [-Wundef]
   #if defined(__GNUC__) && (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
                                                                    ^~~~~~~~~~~
  In file included from /usr/share/mingw-w64/include/string.h:190:0,
                   from crypto/fipsmodule/aes/../../internal.h:263,
                   from crypto/fipsmodule/aes/aes_nohw.c:17:
  /usr/share/mingw-w64/include/sec_api/string_s.h:42:138: error: ISO C does not allow extra ';' outside of a function [-Wpedantic]
     __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_3(errno_t, _strncpy_s_l, char, _Dest, const char *, _Source, size_t, _MaxCount, _locale_t, _Locale);
                                                                                                                                            ^
  /usr/share/mingw-w64/include/sec_api/string_s.h:69:121: error: ISO C does not allow extra ';' outside of a function [-Wpedantic]
     __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, wcsncpy_s, wchar_t, _Dest, const wchar_t *, _Source, size_t, _MaxCount);
                                                                                                                           ^
  /usr/share/mingw-w64/include/sec_api/string_s.h:71:144: error: ISO C does not allow extra ';' outside of a function [-Wpedantic]
     __DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_3(errno_t, _wcsncpy_s_l, wchar_t, _Dest, const wchar_t *, _Source, size_t, _MaxCount, _locale_t, _Locale);
                                                                                                                                                  ^
  thread 'main' panicked at 'execution failed', /cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

rustrial avatar Aug 26 '21 11:08 rustrial

x86_64-w64-mingw32-gcc-posix

On the main branch, but not yet in a release, I added support for compiling for Windows with clang-cl. I didn't try it with GCC. I would be happy to get a PR or some PRs to make that work.

/usr/share/mingw-w64/include/_mingw.h

Warnings in these headers indicate that these headers are also not designed to be (cross)-compiled with GCC? Or least with the warnings the ring enables.

/usr/share/mingw-w64/include/sec_api/string_s.h:42:138: error: ISO C does not allow extra ';' outside of a function [-Wpedantic]

It seems like this pedantic warning is being treated as an error because we have "-pedantic-errors" in ring's build.rs, or similar.

Again, happy to receive PRs to get this working.

briansmith avatar Aug 26 '21 17:08 briansmith

(Also, in case it isn't clear from notifications from GitHub, I reopened this issue.)

briansmith avatar Aug 26 '21 17:08 briansmith

Hi i am facing similar issue , is there any update on this ?

afraz-bdata avatar Aug 31 '22 13:08 afraz-bdata

No plans to do anything special for *-pc-windows-gnu. My understanding is that it's just a matter of setting up the compilers and sysroots, and if you do that, it works. Probably not very convenient.

briansmith avatar Oct 14 '23 03:10 briansmith