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

Linkage error when cross-compiling for aarch64-pc-windows-msvc #453

Closed
rami3l opened this issue Jun 28, 2024 · 43 comments
Closed

Linkage error when cross-compiling for aarch64-pc-windows-msvc #453

rami3l opened this issue Jun 28, 2024 · 43 comments

Comments

@rami3l
Copy link

rami3l commented Jun 28, 2024

Problem:

Originally posted as rustls/rustls-platform-verifier#101, but it turns out it's actually an aws_lc_rs-related issue.

In short, in rust-lang/rustup#3898 we (the Rustup team) are trying to replace the ring backend with aws-lc-rs as a part of Rustup's plan to ship the rustls backend by default (rust-lang/rustup#3806).

When cross-compiling for aarch64-pc-windows-msvc from GitHub's official Windows CI runner however, the following error was generated (see the full error log in the foldable section below):

LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4286: symbol '_wassert' defined in 'libucrt.lib(assert.obj)' is imported by 'libaws_lc_sys-0a41df4d7545123e.rlib(bio.c.obj)'
LINK : warning LNK4286: symbol '_wassert' defined in 'libucrt.lib(assert.obj)' is imported by 'libaws_lc_sys-0a41df4d7545123e.rlib(printf.c.obj)'
[..]
LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(chacha.c.obj)'
[..]
libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_ftell referenced in function file_ctrl
libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp__setmode referenced in function file_ctrl
oldnames.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp__strdup
D:\a\rustup\rustup\target\aarch64-pc-windows-msvc\debug\deps\rustls_platform_verifier-824047c6ba53f86f.dll : fatal error LNK1120: 18 unresolved externals
Full Error log
Compiling rustls-platform-verifier v0.3.1
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.40.33807\\bin\\HostX64\\arm64\\link.exe" "/DEF:C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcjxMRYi\\lib.def" "/NOLOGO" "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcjxMRYi\\symbols.o" "D:\\a\\rustup\\rustup\\target\\aarch64-pc-windows-msvc\\debug\\deps\\rustls_platform_verifier-824047c6ba53f86f.rustls_platform_verifier.d3754e06d5d23fde-cgu.0.rcgu.o" "D:\\a\\rustup\\rustup\\target\\aarch64-pc-windows-msvc\\debug\\deps\\rustls_platform_verifier-824047c6ba53f86f.2kbvfqg2xu4cad5i.rcgu.o" "/LIBPATH:D:\\a\\rustup\\rustup\\target\\aarch64-pc-windows-msvc\\debug\\deps" "/LIBPATH:D:\\a\\rustup\\rustup\\target\\debug\\deps" "/LIBPATH:D:\\a\\rustup\\rustup\\target\\aarch64-pc-windows-msvc\\debug\\build\\aws-lc-sys-62247e93288e9cb7\\out\\build\\artifacts\\" "/LIBPATH:C:\\Users\\runneradmin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\aarch64-pc-windows-msvc\\lib" "D:\\a\\rustup\\rustup\\target\\aarch64
  = note:    Creating library D:\a\rustup\rustup\target\aarch64-pc-windows-msvc\debug\deps\rustls_platform_verifier-824047c6ba53f86f.dll.lib and object D:\a\rustup\rustup\target\aarch64-pc-windows-msvc\debug\deps\rustls_platform_verifier-824047c6ba53f86f.dll.exp
          LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
          LINK : warning LNK4286: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(obj.c.obj)'
          LINK : warning LNK4286: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(refcount_c11.c.obj)'
          LINK : warning LNK4286: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(ex_data.c.obj)'
          LINK : warning LNK4217: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function 'aws_lc_0_18_0_bn_mod_exp_mont_small'
          LINK : warning LNK4286: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj)'
          LINK : warning LNK4286: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(thread_win.c.obj)'
          LINK : warning LNK4286: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(windows.c.obj)'
          LINK : warning LNK4217: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function 'bn_less_than_word_mask'
          LINK : warning LNK4286: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(mem.c.obj)'
          LINK : warning LNK4286: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj)'
          LINK : warning LNK4286: symbol 'malloc' defined in 'libucrt.lib(malloc.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(thread_win.c.obj)'
          LINK : warning LNK4217: symbol '__acrt_iob_func' defined in 'libucrt.lib(_file.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function 'aws_lc_0_18_0_handle_cpu_env'
          LINK : warning LNK4217: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function 'ctr32_add'
          LINK : warning LNK4286: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(mem.c.obj)'
          LINK : warning LNK4286: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj)'
          LINK : warning LNK4286: symbol 'free' defined in 'libucrt.lib(free.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(thread_win.c.obj)'
          LINK : warning LNK4217: symbol 'fflush' defined in 'libucrt.lib(fflush.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function 'check_test'
          LINK : warning LNK4286: symbol 'fflush' defined in 'libucrt.lib(fflush.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(pq_custom_randombytes.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(kyber512r3_ref.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(kyber768r3_ref.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(kyber1024r3_ref.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(ml_kem_512_ipd.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(kem.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(printf.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(kem_methods.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(kem_kyber.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_hmac_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(print.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bio.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_dsa_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_ed25519_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_x25519_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_kem_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_x25519.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_kem.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_rsa_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_ec_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(err_data.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(a_object.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(lhash.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_ed25519.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(convert.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(dsa_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(posix_time.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(poly1305.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(rsa_crypt.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(curve25519_nohw.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bn_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(asn1_compat.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(p_methods.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(dsa.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(rsassa_pss_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(ripemd.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(refcount_c11.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(engine.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(ex_data.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(obj_xref.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(forkunsafe.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(windows.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(obj.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(cpucap.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(e_chacha20poly1305.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(thread_win.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(stack.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(rsa_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(mem.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(cbs.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(e_aesgcmsiv.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(cbb.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(ec_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(evp_asn1.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(crypto.c.obj)'
          LINK : warning LNK4217: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function '_vsnprintf_l'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(chacha.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(curve25519.c.obj)'
          LINK : warning LNK4286: symbol '__stdio_common_vsprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(ecdsa_asn1.c.obj)'
          LINK : warning LNK4217: symbol '__stdio_common_vfprintf' defined in 'libucrt.lib(output.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj)' in function '_vfprintf_l'
          LINK : warning LNK4217: symbol 'qsort' defined in 'libucrt.lib(qsort.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(cbb.c.obj)' in function 'aws_lc_0_18_0_CBB_flush_asn1_set_of'
          LINK : warning LNK4217: symbol '_errno' defined in 'libucrt.lib(errno.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(mem.c.obj)' in function 'aws_lc_0_18_0_OPENSSL_vasprintf_internal'
          LINK : warning LNK4286: symbol '_errno' defined in 'libucrt.lib(errno.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj)'
          LINK : warning LNK4286: symbol '_errno' defined in 'libucrt.lib(errno.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj)'
          LINK : warning LNK4217: symbol 'fclose' defined in 'libucrt.lib(fclose.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj)' in function 'aws_lc_0_18_0_BIO_new_file'
          LINK : warning LNK4217: symbol '_fileno' defined in 'libucrt.lib(fileno.obj)' is imported by 'libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj)' in function 'file_ctrl'
          libaws_lc_sys-2799e0ca1159a8ce.rlib(bio.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(printf.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(posix_time.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(poly1305.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(a_object.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(lhash.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(curve25519_nohw.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(asn1_compat.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(convert.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(dsa_asn1.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(stack.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(engine.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(ex_data.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(ripemd.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(mem.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(cbs.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(e_chacha20poly1305.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(chacha.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(cbb.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(rsa_asn1.c.obj) : error LNK2001: unresolved external symbol __imp__wassert
          libaws_lc_sys-2799e0ca1159a8ce.rlib(bcm.c.obj) : error LNK2019: unresolved external symbol __imp___stdio_common_vsscanf referenced in function _vsscanf_l
          libaws_lc_sys-2799e0ca1159a8ce.rlib(mem.c.obj) : error LNK2019: unresolved external symbol __imp_realloc referenced in function aws_lc_0_18_0_OPENSSL_vasprintf_internal
          libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj) : error LNK2019: unresolved external symbol __imp_strerror referenced in function err_reason_error_string
          libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj) : error LNK2019: unresolved external symbol __imp_fputs referenced in function print_errors_to_file
          libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj) : error LNK2019: unresolved external symbol __imp_strdup referenced in function aws_lc_0_18_0_ERR_set_error_data
          oldnames.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp_strdup
          libaws_lc_sys-2799e0ca1159a8ce.rlib(err.c.obj) : error LNK2019: unresolved external symbol __imp_bsearch referenced in function aws_lc_0_18_0_ERR_restore_state
          libaws_lc_sys-2799e0ca1159a8ce.rlib(obj.c.obj) : error LNK2001: unresolved external symbol __imp_bsearch
          libaws_lc_sys-2799e0ca1159a8ce.rlib(stack.c.obj) : error LNK2019: unresolved external symbol __imp_qsort_s referenced in function aws_lc_0_18_0_OPENSSL_sk_sort
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_fopen referenced in function aws_lc_0_18_0_BIO_new_file
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_fwrite referenced in function file_write
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_fread referenced in function file_read
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_ferror referenced in function file_read
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_fgets referenced in function file_gets
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_fseek referenced in function file_ctrl
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_feof referenced in function file_ctrl
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_ftell referenced in function file_ctrl
          libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp__setmode referenced in function file_ctrl
          oldnames.lib(strdup.obi) : error LNK2001: unresolved external symbol __imp__strdup
          D:\a\rustup\rustup\target\aarch64-pc-windows-msvc\debug\deps\rustls_platform_verifier-824047c6ba53f86f.dll : fatal error LNK1120: 18 unresolved externals
          
error: could not compile `rustls-platform-verifier` (lib) due to 1 previous error

You can also go to https://github.com/rust-lang/rustup/actions/runs/9624188283/job/26547561849 for the full CI log.

In addition, to prove that this actually has nothing to do with rustls-platform-verifier, another build error without the latter was reproduced in rust-lang/rustup#3917 as https://github.com/rust-lang/rustup/actions/runs/9708177268/job/26794554219.

Relevant details

The lockfile includes the following versions for aws-lc-* dependencies:

[[package]]
name = "aws-lc-fips-sys"
version = "0.12.9"

[[package]]
name = "aws-lc-rs"
version = "1.7.3"

[[package]]
name = "aws-lc-sys"
version = "0.18.0"

System information for the official GitHub runner in question:

Current runner version: '2.317.0'
Operating System
  Microsoft Windows Server 2022
  10.0.20348
  Datacenter
Runner Image
  Image: windows-2022
  Version: 20240624.1.0
  Included Software: https://github.com/actions/runner-images/blob/win22/20240624.1/images/windows/Windows2022-Readme.md
  Image Release: https://github.com/actions/runner-images/releases/tag/win22%2F20240624.1
Runner Image Provisioner
  2.0.370.1

Another interesting detail is that this seems to work without issues when compiling natively on an ARM64 Windows machine:

I was able to compile and run the tests for rustls-platform-verifier in an ARM64 Windows 11 VM with the aws_lc_rs backend earlier today. The steps I took to setup the environment were:

  • Installed the latest CMake from their website
  • Installed the latest Ninja from GitHub releases
  • Download the latest Visual Studio 2022 Tools installer
  • Installed these components:
    • Windows 11 SDK
    • MSVC v143 C++ ARM64 build tools

I then:

  • Edited rustls-platform-verifier's main branch to use aws_lc_rs everywhere ring currently is
  • Ran cargo test.

With this setup, I don't get the errors you reported FWIW. @ctz mentioned this in the project Discord but it looks like there isn't a compatible ucrt available to your build since all the missing symbols should be coming from it. I saw the VS installer install a ARM64 ucrt implementation, so maybe that's part of what's missing?
Originally posted by @complexspaces in rustls/rustls-platform-verifier#101 (comment)

Many thanks in advance!

@justsmth
Copy link
Contributor

Thanks for the report. I'll try to reproduce this.

For reference, we do have a CI job that tests cross-compiling to aarch64-pc-windows-msvc -- this test might need to be expanded to include more variety in its build options.

@justsmth
Copy link
Contributor

justsmth commented Jun 28, 2024

To help get some clarity, I'll narrow my focus to just that first error you listed:

libaws_lc_sys-2799e0ca1159a8ce.rlib(file.c.obj) : error LNK2019: unresolved external symbol __imp_ftell referenced in function file_ctrl

From what I can tell, this relates to the inability for the linker to resolve the ftell invocation here:

static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
...
    case BIO_CTRL_INFO:
      ret = ftell(fp);
      break;
...

On Windows, we're specifically including fcntl.h and io.h:

#if defined(OPENSSL_WINDOWS)
#include <fcntl.h>
#include <io.h>
#endif  // OPENSSL_WINDOWS

I'm not sure this gets us any close to a root-cause, but for ftell we should be including "stdio.h" (which we do directly above). I wonder if something in these windows-specific header files is renaming this symbol to __imp_ftell preventing it from being found by the linker.

@rami3l
Copy link
Author

rami3l commented Jun 28, 2024

Thanks for the report. I'll try to reproduce this.

For reference, we do have a CI job that tests cross-compiling to aarch64-pc-windows-msvc -- this test might need to be expanded to include more variety in its build options.

@justsmth Thanks for the prompt response!

I'm aware that you have a CI workflow for this case, and that was the first thing for me to check out when I encountered this error just in case I'd missed something.

However, I realized that you really just built the lib. In our original build log, the linkage failure happened way beyond the point of building aws-lc-*, and that was why I originally reported the issue to rustls-platform-verifier.

@justsmth
Copy link
Contributor

justsmth commented Jun 28, 2024

A possible lead -- I see some mingw headers with macro definitions that could create a __imp_ftell symbol:

❯ find . -name "*.h" | xargs grep __imp_
./mingw64/include/_mingw_mac.h:#  define __MINGW_IMP_SYMBOL(sym) __imp_##sym
./mingw64/include/_mingw_mac.h:#  define __MINGW_IMP_LSYMBOL(sym) __imp_##sym
./mingw64/include/_mingw_mac.h:#  define __MINGW_IMP_LSYMBOL(sym) __imp__##sym
./ucrt64/include/_mingw_mac.h:#  define __MINGW_IMP_SYMBOL(sym) __imp_##sym
./ucrt64/include/_mingw_mac.h:#  define __MINGW_IMP_LSYMBOL(sym) __imp_##sym
./ucrt64/include/_mingw_mac.h:#  define __MINGW_IMP_LSYMBOL(sym) __imp__##sym

Perhaps our build is picking up a MINGW header?

@rami3l
Copy link
Author

rami3l commented Jun 28, 2024

Could it be related to this thread? https://learn.microsoft.com/en-us/answers/questions/576680/visual-studio-2017-c-linking-error-lnk2019-unresol

At least it does look like this has something to do with how the lib handles CRT.

@rami3l
Copy link
Author

rami3l commented Jun 28, 2024

Could it be related to this thread? https://learn.microsoft.com/en-us/answers/questions/576680/visual-studio-2017-c-linking-error-lnk2019-unresol

At least it does look like this has something to do with how the lib handles UCRT.

Indeed, https://stackoverflow.com/a/3007915 and OpenMathLib/OpenBLAS#2825 also talk about /MT and /MD compiler options. I'm becoming more and more convinced that this info will help.

@justsmth
Copy link
Contributor

Thanks for your help diagnosing this!

I suspect we should be using static_crt(true) with our CMake config: https://github.com/rust-lang/cmake-rs/blob/c4a60dd154dd90e469dffc41a1faa717704f90b3/src/lib.rs#L333

I'll put the change into this PR:

@rami3l
Copy link
Author

rami3l commented Jun 28, 2024

@justsmth Thanks! Tomorrow I should be able to add a patched dependency to point to the PR branch and see if your changes work for us.

@rami3l
Copy link
Author

rami3l commented Jun 29, 2024

@justsmth I just tried again with the patched dependency and unfortunately the fix didn't work: https://github.com/rust-lang/rustup/actions/runs/9720192943/job/26831234964?pr=3917

And it's almost the same kind of error... I'm confused.

I wonder if it's possible to at least try to build the test binary (so in addition to the library itself) for ARM64 Windows and see if the linkage problem can be reproduced there?

@justsmth
Copy link
Contributor

I wonder if it's possible to at least try to build the test binary (so in addition to the library itself) for ARM64 Windows and see if the linkage problem can be reproduced there?

Good idea. I'll try to set this up tomorrow.

@justsmth
Copy link
Contributor

justsmth commented Jun 30, 2024

I added --all-targets in that PR to our CI's "cargo build" commands for arm64 Windows, but (unfortunately) it's not reproducing the build failure: https://github.com/aws/aws-lc-rs/actions/runs/9734469537/job/26862526216?pr=452. :-(

Please let me know any guidance you might have related to reproducing these build problems locally. I'll work tomorrow on trying to reproduce this and the other (AT_HWCAP2) build failure.

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

@justsmth Thanks anyway for having tried!

I still believe there's a CRT conflict somewhere but I'm not sure what kind of conflict it is... I cross-checked our setups for the Windows compilation tests and frankly speaking I cannot find any significant differences...

Maybe @ChrisDenton can shed a light on this issue? (x_x)

@ChrisDenton
Copy link

I've not looked into this yet but I can perhaps give some more information on the MSVC C runtime.

There are essentially four mutually exclusive C runtime libraries. Scroll down that page to the table that lists /MT etc. I'll reproduce some of it here with some Rust notes:

lib C option Rust
libcmt.lib /MT target_feature=+crt_static
libcmtd.lib /MTd N/A
msvcrt.lib /MD the default
msvcrtd.lib /MDd N/A

All libraries and the final binary should use the same CRT, whether they're compiled in C/C++ or Rust. Stable Rust does not currently support the debug CRTs (the ones ending in d) but you might be able to override it by explicitly linking one of them so that the linker sees it first.

In nightly you can use, for example, /nodefaultlib:msvcrt to disable the default before adding the one you need.

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

@ChrisDenton Aha! Thanks for your "Rust" column! I immediately spotted:

env:
  RUSTFLAGS: -Ctarget-feature=+crt-static

https://github.com/rust-lang/rustup/blob/efa576d8fbb4b98cf6dc8770afebc9b1e647f00b/ci/actions-templates/windows-builds-template.yaml#L13

Does removing this mean our MSVC build can no longer run if our users don't install MSVCRT externally?

Anyway, I removed that and most errors are gone (as we must have used /MT on our side to link against aws-lc's /MD), but for the debug build we still have the following (see https://github.com/rust-lang/rustup/actions/runs/9739316249/job/26874321466?pr=3898):

LINK : warning LNK4098: defaultlib 'msvcrtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

I assume this is due to building aws-lc with cmake somehow relies on /MDd?

I think at least I have some ideas about how to get ourselves out of this situation now. So basically this project's build script (when calling cmake) has to find a way to pass the correct CRTs on Windows to be used with Rust, so:

  1. Use /MD even if conventionally one should use /MDd;
  2. Better yet, use /MT on +crt-static.

@justsmth Another crucial difference between our setups is that we use the following linker option on Windows MSVC as well:

println!("cargo:rustc-link-arg-bin=rustup-init=/WX");

This was originally added by @ChrisDenton to prevent cargo from silencing linkage warnings, which is probably why your CI happens to turn green.

@ChrisDenton
Copy link

Does removing this mean our MSVC build can no longer run if our users don't install MSVCRT externally?

Yes. It would either need to be installed be the user or else the vcruntime DLL needs to be distributed with the application (Microsoft prefers people do the former).

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

Does removing this mean our MSVC build can no longer run if our users don't install MSVCRT externally?

Yes. It would either need to be installed be the user or else the vcruntime DLL needs to be distributed with the application (Microsoft prefers people do the former).

@ChrisDenton Okay... That's rather unfortunate since we won't want to make a Rust dev environment even harder to setup... It's pretty hard for newcomers already :'(

@ChrisDenton
Copy link

Yes, the proper fix would be to use the C/C++ libraries that are built against the same CRT as rustup wants. But, as I say, I've not looked into how they're built or what control rustup has (or not) over this.

@justsmth
Copy link
Contributor

justsmth commented Jul 1, 2024

I assume this is due to building aws-lc with cmake somehow relies on /MDd?

I think this might be the issue. I did see on Windows that /MDd is used for "debug" builds but not for "relwithdebinfo". I pushed another commit so that on Windows we build AWS-LC as either "release" or "relwithdebinfo", but not "debug": cc75014

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

I assume this is due to building aws-lc with cmake somehow relies on /MDd?

I think this might be the issue. I did see on Windows that /MDd is used for "debug" builds but not for "relwithdebinfo". I pushed another commit so that on Windows we build AWS-LC as either "release" or "relwithdebinfo", but not "debug": cc75014

@justsmth Thanks a lot for your prompt response!

Given that the previous /MD attempt was on your latest release (rather than the PR branch) just to test if dynamically linked CRT works at all (as we'd still like to have statically linked CRT (/MT) to simplify everyone's Rust workflow), I'd like to give some extra suggestions here:

  1. If you're adding support for statically-linked CRT, it's probably better to make /MT conditional. I'm not sure why previously our -Ctarget-feature=+crt-static didn't work with your fef6a89's static_crt(true), but it seems to me that the right thing to do is to link CRT statically only when cargo is signaled to do so (not sure if there's an API for this or not).

  2. It probably makes sense to enable /WX (like we currently do in Linkage error when cross-compiling for aarch64-pc-windows-msvc #453 (comment)) to ensure that the warning is really gone. If you want to make this CI-exclusive, you may add something like RUSTFLAGS: -Clink-arg=/WX to your workflow's env section like we did above (not sure about the syntax, but should be doable).

I'd like to help you with the testing on our side if necessary, just ping me back when it's time!

@justsmth
Copy link
Contributor

justsmth commented Jul 1, 2024

Latest commit: 37884d0


If you're adding support for statically-linked CRT, it's probably better to make /MT conditional. I'm not sure why previously our -Ctarget-feature=+crt-static didn't work with your fef6a89ff97782e0ed098fc317a4c7c493629060's static_crt(true), but it seems to me that the right thing to do is to link CRT statically only when cargo is signaled to do so (not sure if there's an API for this or not).

  • I have the build script check whether the "CARGO_ENCODED_RUSTFLAGS" environment variable contains: -Ctarget-feature=+crt-static:
        if cargo_env("CARGO_ENCODED_RUSTFLAGS").contains("-Ctarget-feature=+crt-static") {
            // See issue: https://github.com/aws/aws-lc-rs/issues/453
            cmake_cfg.static_crt(true);
        }

It probably makes sense to enable /WX (like we currently do in #453 (comment)) to ensure that the warning is really gone. If you want to make this CI-exclusive, you may add something like RUSTFLAGS: -Clink-arg=/WX to your workflow's env section like we did above (not sure about the syntax, but should be doable).

  • I've added this to the environment of the Windows build CI jobs.

@justsmth
Copy link
Contributor

justsmth commented Jul 1, 2024

Somehow that RUSTFLAGS environment variable is getting mangled: 🤔

Run cargo test -p aws-lc-rs --target x86_64-pc-windows-gnu --features bindgen
  cargo test -p aws-lc-rs --target x86_64-pc-windows-gnu --features bindgen
  shell: C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
  env:
    RUST_BACKTRACE: 1
    RUST_NIGHTLY_TOOLCHAIN: nightly-2024-05-22
    RUSTFLAGS: -Clink-arg=/WX
    CARGO_HOME: C:\Users\runneradmin/.cargo
    CARGO_INCREMENTAL: 0
    CARGO_TERM_COLOR: always
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe - --crate-name ___ --print=file-names '-Clink-arg=C:/Program' Files/Git/WX --target x86_64-pc-windows-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit code: 1)
  --- stderr
  error: multiple input filenames provided (first two filenames are `-` and `Files/Git/WX`)

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

Somehow that RUSTFLAGS environment variable is getting mangled: 🤔

Run cargo test -p aws-lc-rs --target x86_64-pc-windows-gnu --features bindgen
  cargo test -p aws-lc-rs --target x86_64-pc-windows-gnu --features bindgen
  shell: C:\Program Files\Git\bin\bash.EXE --noprofile --norc -e -o pipefail {0}
  env:
    RUST_BACKTRACE: 1
    RUST_NIGHTLY_TOOLCHAIN: nightly-2024-05-22
    RUSTFLAGS: -Clink-arg=/WX
    CARGO_HOME: C:\Users\runneradmin/.cargo
    CARGO_INCREMENTAL: 0
    CARGO_TERM_COLOR: always
error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe - --crate-name ___ --print=file-names '-Clink-arg=C:/Program' Files/Git/WX --target x86_64-pc-windows-gnu --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit code: 1)
  --- stderr
  error: multiple input filenames provided (first two filenames are `-` and `Files/Git/WX`)

@justsmth Seems to work perfectly for aarch64-pc-windows-msvc though! What could be the difference here? 🤔 (cargo xwin is not using link.exe so the flag makes no sense I guess.)

Looks like it's the shell being used!

@justsmth
Copy link
Contributor

justsmth commented Jul 1, 2024

Looks like it's the shell being used!

🤦🏻 Thanks! 😄

@justsmth
Copy link
Contributor

justsmth commented Jul 1, 2024

With the -Clink-arg=/WX, we now get a build failure on x86:

  LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

  LINK : error LNK1218: warning treated as error; no output file generated

It's different that the one originally reported, but that might be due (in part) to the other changes that were made to the build by the PR.

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

@justsmth It's pretty late at my place now so I'll take a closer look tomorrow. Anyway, I very much appreciate your efforts and I'm so glad to see things moving forward!

@rami3l
Copy link
Author

rami3l commented Jul 1, 2024

... also I'm curious about what will happen if you duplicate a current Windows MSVC test and set RUSTFLAGS: -Ctarget-feature=+crt-static to it. Looks useful if you want to verify if the /MT fix is working 🤔

That said, I'm glad to see that the /MD case is mostly fixed. Not sure about the i686 case, looks like it's still using /MDd if I'm not mistaken?

@rami3l
Copy link
Author

rami3l commented Jul 2, 2024

@justsmth Not sure whether it's getting better or not, but with 63bd01b, I'm now getting this with +crt-static:

error: could not find native static library `aws_lc_0_19_0_crypto`, perhaps an -L flag is missing?

The following warnings were emitted during compilation:

warning: aws-lc-sys@0.19.0: Generating bindings - internal bindgen. Platform: aarch64-pc-windows-msvc

error: could not compile `aws-lc-sys` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...

... looks like we're back with cargo errors now instead of the cmake ones, so it's probably good news?

@justsmth
Copy link
Contributor

justsmth commented Jul 2, 2024

... looks like we're back with cargo errors now instead of the cmake ones, so it's probably good news?

Well... today, the good news is that I managed to maintain my sanity. :-)

The problem with our aarch64 build relates to our use of Ninja. But unfortunately, I've not been able to get the build to succeed on "aarch64" w/o it. It seems the default "MSBuild" generator doesn't want to invoke "clang-cl" on the assembly files. The build errors look like this:

    Building Custom Rule D:/a/aws-lc-rs/aws-lc-rs/aws-lc-sys/aws-lc/crypto/CMakeLists.txt
    D:\a\aws-lc-rs\aws-lc-rs\target\aarch64-pc-windows-msvc\debug\build\aws-lc-sys-d9326ee179f6734f\out\build\aws-lc\crypto\crypto_objects.dir\Debug\chacha-armv8.obj: no such file or directory
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(1599,5): error MSB6006: "llvm-lib.exe" exited with code 1. [D:\a\aws-lc-rs\aws-lc-rs\target\aarch64-pc-windows-msvc\debug\build\aws-lc-sys-d9326ee179f6734f\out\build\aws-lc\crypto\crypto.vcxproj]

With Ninja the build completes but when the test binaries link to it, a warning/error is generated relating to "defaultlib 'MSVCRTD' conflicts with use of other libs":

  = note:    Creating library D:\a\aws-lc-rs\aws-lc-rs\target\aarch64-pc-windows-msvc\debug\deps\digest_test-d1f6e816284133e7.lib and object D:\a\aws-lc-rs\aws-lc-rs\target\aarch64-pc-windows-msvc\debug\deps\digest_test-d1f6e816284133e7.exp

          LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

          LINK : error LNK1218: warning treated as error; no output file generated

I think the best path forward would be for us to eliminate our need for Ninja, but a little more digging is needed.

@justsmth
Copy link
Contributor

justsmth commented Jul 2, 2024

One thing to note is that I attempted to fix the Ninja build by executing vcvarsall.bat to setup the build environment properly: 63bd01b. (This was something needed for our FIPS build.) However, this seemed to not have any impact on the build errors we were getting.

@rami3l
Copy link
Author

rami3l commented Jul 2, 2024

Well... today, the good news is that I managed to maintain my sanity. :-)

@justsmth Oh, I'm sorry to hear that 🙇‍♀️ Thanks again for your hard work so far!

I think the best path forward would be for us to eliminate our need for Ninja, but a little more digging is needed.

On our side we don't have a specific deadline ahead for shipping a new version with aws-lc-rs, so just take your time ❤️

@justsmth
Copy link
Contributor

justsmth commented Jul 2, 2024

Thanks! These types of build issues are difficult to reason about logically and the outcome of a change attempt often seems arbitrary, making it a little challenging to one's "sanity". But I'm glad we're sorting this out. The result will be a better experience for our users. 😃

@rami3l
Copy link
Author

rami3l commented Jul 2, 2024

Thanks! These types of build issues are difficult to reason about logically and the outcome of a change attempt often seems arbitrary, making it a little challenging to one's "sanity".

I can relate, as I had also force pushed quite a few times on my PR only to see the CI turning red, thinking that might be my own problem, before I finally decided to report this as an issue 🤝

But I'm glad we're sorting this out. The result will be a better experience for our users. 😃

Definitely! Looking forward to it 🚄

bwoebi added a commit to DataDog/libdatadog that referenced this issue Jul 8, 2024
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
bwoebi added a commit to DataDog/libdatadog that referenced this issue Jul 8, 2024
Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
bwoebi added a commit to DataDog/libdatadog that referenced this issue Jul 9, 2024
* Bump rustls version to 0.23

We were running into symbol issues with older rustls versions, see briansmith/ring#1808.

Note that the new rustls version requires nasm to be installed on windows, so we install it in CI.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

* Require at least aws-lc-rs 1.8

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

* Use ring instead of aws-lc-sys due to aws/aws-lc-rs#453

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

* Use ring for windows only, as aws-lc-sys has link issues on windows. But aws-lc-sys is actually preferable.

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>

---------

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
justsmth added a commit to aws/aws-lc that referenced this issue Jul 15, 2024
### Issues:
* Addresses: aws/aws-lc-rs#453

### Description of changes: 
* When building for Windows/ARM64 with the "Visual Studio" generator
(instead of Ninja) the "*.S" assembly source files for libraries are
ignored.
* This change provides a custom command to assemble the require objects
files and adds them to the list of sources for the library.

### Call-outs:
* See related aws-lc-rs PR: aws/aws-lc-rs#452

### Testing
* I've added CI tests to build for Windows using the "Visual Studio"
generator.


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
@awakecoding
Copy link

What's the current status for aarch64-pc-windows-msvc building on Windows? A colleague of mine wasted a few days on this after rustls was updated to use aws-lc-rs, and now that I'm back from vacation, I wasted a few hours on it myself, only to be even more confused. Can the MSVC clang-llvm component be used for the the build, or does it truly require the clang-llvm installer from llvm.org? Why is it using a different CMake generator based on the CPU target on Windows? It's unclear what kind of environment variables we need to setup to get it working when it's mixed with clang-cl and the Visual Studio environment variables to find the library and include directories, etc.

@awakecoding
Copy link

awakecoding commented Jul 15, 2024

Thanks for the report. I'll try to reproduce this.

For reference, we do have a CI job that tests cross-compiling to aarch64-pc-windows-msvc -- this test might need to be expanded to include more variety in its build options.

I noticed that while investigating what the GitHub Actions workflow did - we're compiling to Windows x64 + arm64 from Windows x64, nothing fancy. At a bare minimum, compilation on Windows using MSVC should be tested, as it is the most common over Linux cross-compilation using clang-cl

@justsmth
Copy link
Contributor

justsmth commented Jul 15, 2024

I'm sorry about the difficulty with building our package on Windows. We're working to improve the build experience for Windows users. We have a few build fixes to release this week, and several further improvements are planned for the near future.

Feel free to reference any of the GitHub CI configurations we have setup:

What's the current status for aarch64-pc-windows-msvc building on Windows?

We've merged a required Windows/ARM64 build fix upstream, and plan to release the fix as part of aws-lc-rs v1.8.1 (using aws-lc-sys v0.20.0).

Can the MSVC clang-llvm component be used for the the build, or does it truly require the clang-llvm installer from llvm.org?

We support MSVC's ClangCL (clang-cl). I've tried building with the ClangCL from llvm.org, but there were linker errors that still need to be investigated.

Why is it using a different CMake generator based on the CPU target on Windows?

Going forward, we will support the "Visual Studio"/"MSBuild" generator for (non-FIPS) MSVC builds on Windows x86/x86_64/aarch64 platforms.

The issue is (or was) that the "Visual Studio"/"MSBuild" generator on ARM64 ignores the assembly files required for our build. (Other projects have also noted this issue.) We currently require Ninja as CMake's "generator" for Windows/ARM64, but with this issue now addressed in AWS-LC, that requirement will go away with our v1.8.1 release.

justsmth pushed a commit to justsmth/aws-lc-rs that referenced this issue Jul 16, 2024
diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs
index b4914d1ebc..9eb4c714a2 100644
--- a/aws-lc-sys/builder/cmake_builder.rs
+++ b/aws-lc-sys/builder/cmake_builder.rs
@@ -3,8 +3,8 @@

 use crate::OutputLib::{Crypto, RustWrapper, Ssl};
 use crate::{
-    cargo_env, emit_warning, execute_command, is_no_asm, option_env, target, target_arch,
-    target_env, target_os, target_underscored, target_vendor, OutputLibType,
+    cargo_env, emit_warning, execute_command, is_no_asm, is_prebuilt_nasm, option_env, target,
+    target_arch, target_env, target_os, target_underscored, target_vendor, OutputLibType,
 };
 use std::env;
 use std::ffi::OsStr;
@@ -168,6 +168,23 @@ impl CmakeBuilder {
             }
         }

+        if target_os() == "windows" && target_arch() == "x86_64" && is_prebuilt_nasm() {
+            emit_warning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+            emit_warning("!!!   Using pre-built NASM binaries   !!!");
+            emit_warning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+
+            let script_path = self
+                .manifest_dir
+                .join("builder")
+                .join("prebuilt-nasm.bat")
+                .display()
+                .to_string();
+            let script_path = script_path.replace(r"\", "/");
+
+            cmake_cfg.define("CMAKE_ASM_NASM_COMPILER", script_path.as_str());
+            cmake_cfg.define("CMAKE_VERBOSE_MAKEFILE", "1");
+        }
+
         if target_underscored() == "aarch64_pc_windows_msvc" {
             cmake_cfg.generator("Ninja");
             cmake_cfg.define("CMAKE_C_COMPILER", "clang-cl");
@@ -212,7 +229,11 @@ impl crate::Builder for CmakeBuilder {
         let mut missing_dependency = false;

         if target_os() == "windows" {
-            if target_arch() == "x86_64" && !test_nasm_command() && !is_no_asm() {
+            if target_arch() == "x86_64"
+                && !test_nasm_command()
+                && !is_no_asm()
+                && !is_prebuilt_nasm()
+            {
                 eprintln!(
                     "Consider setting `AWS_LC_SYS_NO_ASM` in the environment for development builds.\
                 See User Guide about the limitations: https://aws.github.io/aws-lc-rs/index.html"
diff --git a/aws-lc-sys/builder/main.rs b/aws-lc-sys/builder/main.rs
index 866d2055b8..d9936718a6 100644
--- a/aws-lc-sys/builder/main.rs
+++ b/aws-lc-sys/builder/main.rs
@@ -313,6 +313,7 @@ static mut AWS_LC_SYS_NO_PREFIX: bool = false;
 static mut AWS_LC_SYS_INTERNAL_BINDGEN: bool = false;
 static mut AWS_LC_SYS_EXTERNAL_BINDGEN: bool = false;
 static mut AWS_LC_SYS_NO_ASM: bool = false;
+static mut AWS_LC_SYS_PREBUILT_NASM: bool = false;

 fn initialize() {
     unsafe {
@@ -322,6 +323,7 @@ fn initialize() {
         AWS_LC_SYS_EXTERNAL_BINDGEN =
             env_var_to_bool("AWS_LC_SYS_EXTERNAL_BINDGEN").unwrap_or(false);
         AWS_LC_SYS_NO_ASM = env_var_to_bool("AWS_LC_SYS_NO_ASM").unwrap_or(false);
+        AWS_LC_SYS_PREBUILT_NASM = env_var_to_bool("AWS_LC_SYS_PREBUILT_NASM").unwrap_or(false);
     }

     if !is_external_bindgen() && (is_internal_bindgen() || !has_bindgen_feature()) {
@@ -369,6 +371,10 @@ fn is_no_asm() -> bool {
     unsafe { AWS_LC_SYS_NO_ASM }
 }

+fn is_prebuilt_nasm() -> bool {
+    unsafe { AWS_LC_SYS_PREBUILT_NASM }
+}
+
 fn has_bindgen_feature() -> bool {
     cfg!(feature = "bindgen")
 }
diff --git a/aws-lc-sys/builder/prebuilt-nasm.bat b/aws-lc-sys/builder/prebuilt-nasm.bat
new file mode 100644
index 0000000000..9c761db12a
--- /dev/null
+++ b/aws-lc-sys/builder/prebuilt-nasm.bat
@@ -0,0 +1,21 @@
+@echo off
+set "ScriptDir=%~dp0"
+set "ScriptDir=%ScriptDir:~0,-1%"
+:loop
+set "arg1=%~1"
+if "%arg1%"=="-o" goto end
+if "%arg1%"=="" goto failure
+shift
+goto loop
+:end
+shift
+set "path=%~1"
+for %%f in ("%path%") do set "filename=%%~nxf"
+copy "%ScriptDir%\prebuilt-nasm\%filename%" "%path%"
+exit 0
+
+:failure
+echo PATH: %path% 1>&2
+echo FILENAME: %filename% 1>&2
+echo ScriptDir: %ScriptDir% 1>&2
+exit 1
\ No newline at end of file
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aes128gcmsiv-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aes128gcmsiv-x86_64.obj
new file mode 100644
index 0000000000..3caa1c64f7
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aes128gcmsiv-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-avx512.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-avx512.obj
new file mode 100644
index 0000000000..99dff121d2
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-avx512.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-x86_64.obj
new file mode 100644
index 0000000000..a40c77f839
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-sha1-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha1-x86_64.obj
new file mode 100644
index 0000000000..9b14149bc8
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha1-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-sha256-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha256-x86_64.obj
new file mode 100644
index 0000000000..de492cd645
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha256-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-x86_64.obj
new file mode 100644
index 0000000000..77ef35b43f
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-xts-avx512.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-xts-avx512.obj
new file mode 100644
index 0000000000..45e257d9ff
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-xts-avx512.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/chacha-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/chacha-x86_64.obj
new file mode 100644
index 0000000000..37a378b223
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/chacha-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/chacha20_poly1305_x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/chacha20_poly1305_x86_64.obj
new file mode 100644
index 0000000000..05cee5a3d1
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/chacha20_poly1305_x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/ghash-ssse3-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/ghash-ssse3-x86_64.obj
new file mode 100644
index 0000000000..42566f60be
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/ghash-ssse3-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/ghash-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/ghash-x86_64.obj
new file mode 100644
index 0000000000..3706db4563
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/ghash-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/md5-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/md5-x86_64.obj
new file mode 100644
index 0000000000..6ebd3e7916
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/md5-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/p256-x86_64-asm.obj b/aws-lc-sys/builder/prebuilt-nasm/p256-x86_64-asm.obj
new file mode 100644
index 0000000000..ef2ab1e558
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/p256-x86_64-asm.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/p256_beeu-x86_64-asm.obj b/aws-lc-sys/builder/prebuilt-nasm/p256_beeu-x86_64-asm.obj
new file mode 100644
index 0000000000..98b6522f5a
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/p256_beeu-x86_64-asm.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/rdrand-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/rdrand-x86_64.obj
new file mode 100644
index 0000000000..25ecc304a0
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/rdrand-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/rsaz-avx2.obj b/aws-lc-sys/builder/prebuilt-nasm/rsaz-avx2.obj
new file mode 100644
index 0000000000..39d98ee7b7
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/rsaz-avx2.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/sha1-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/sha1-x86_64.obj
new file mode 100644
index 0000000000..28f049ba7f
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/sha1-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/sha256-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/sha256-x86_64.obj
new file mode 100644
index 0000000000..88fa74e3cb
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/sha256-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/sha512-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/sha512-x86_64.obj
new file mode 100644
index 0000000000..258d354f4e
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/sha512-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/trampoline-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/trampoline-x86_64.obj
new file mode 100644
index 0000000000..3370a1073f
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/trampoline-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/vpaes-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/vpaes-x86_64.obj
new file mode 100644
index 0000000000..1e24b23b01
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/vpaes-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont.obj b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont.obj
new file mode 100644
index 0000000000..5a841d3ee3
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont5.obj b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont5.obj
new file mode 100644
index 0000000000..135436db3b
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont5.obj differ

diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs
index ce6dec782a..a769d68da1 100644
--- a/aws-lc-sys/builder/cmake_builder.rs
+++ b/aws-lc-sys/builder/cmake_builder.rs
@@ -3,7 +3,7 @@

 use crate::OutputLib::{Crypto, RustWrapper, Ssl};
 use crate::{
-    cargo_env, emit_warning, execute_command, is_crt_static, is_no_asm, option_env, target,
+    cargo_env, emit_warning, execute_command, is_crt_static, is_no_asm, is_prebuilt_nasm, option_env, target,
     target_arch, target_env, target_os, target_underscored, target_vendor, OutputLibType,
 };
 use std::env;
@@ -135,7 +135,7 @@ impl CmakeBuilder {

         // See issue: aws#453
         if target_os() == "windows" {
-            Self::configure_windows(&mut cmake_cfg);
+            self.configure_windows(&mut cmake_cfg);
         }

         // If the build environment vendor is Apple
@@ -162,13 +162,30 @@ impl CmakeBuilder {
         }

         if target_env() == "ohos" {
-            Self::configure_open_harmony(&mut cmake_cfg);
+            self.configure_open_harmony(&mut cmake_cfg);
         }

         cmake_cfg
     }

-    fn configure_windows(cmake_cfg: &mut cmake::Config) {
+    fn configure_windows(&self, cmake_cfg: &mut cmake::Config) {
+        if target_arch() == "x86_64" && is_prebuilt_nasm() {
+            emit_warning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+            emit_warning("!!!   Using pre-built NASM binaries   !!!");
+            emit_warning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+
+            let script_path = self
+                .manifest_dir
+                .join("builder")
+                .join("prebuilt-nasm.bat")
+                .display()
+                .to_string();
+            let script_path = script_path.replace(r"\", "/");
+
+            cmake_cfg.define("CMAKE_ASM_NASM_COMPILER", script_path.as_str());
+            cmake_cfg.define("CMAKE_VERBOSE_MAKEFILE", "1");
+        }
+
         match (target_env().as_str(), target_arch().as_str()) {
             ("msvc", "aarch64") => {
                 cmake_cfg.generator_toolset(format!(
@@ -200,7 +217,7 @@ impl CmakeBuilder {
         }
     }

-    fn configure_open_harmony(cmake_cfg: &mut cmake::Config) {
+    fn configure_open_harmony(&self, cmake_cfg: &mut cmake::Config) {
         const OHOS_NDK_HOME: &str = "OHOS_NDK_HOME";
         if let Ok(ndk) = env::var(OHOS_NDK_HOME) {
             cmake_cfg.define(
@@ -253,7 +270,11 @@ impl crate::Builder for CmakeBuilder {
         let mut missing_dependency = false;

         if target_os() == "windows" {
-            if target_arch() == "x86_64" && !test_nasm_command() && !is_no_asm() {
+            if target_arch() == "x86_64"
+                && !test_nasm_command()
+                && !is_no_asm()
+                && !is_prebuilt_nasm()
+            {
                 eprintln!(
                     "Consider setting `AWS_LC_SYS_NO_ASM` in the environment for development builds.\
                 See User Guide about the limitations: https://aws.github.io/aws-lc-rs/index.html"
diff --git a/aws-lc-sys/builder/main.rs b/aws-lc-sys/builder/main.rs
index 4bf220138b..1241db16b4 100644
--- a/aws-lc-sys/builder/main.rs
+++ b/aws-lc-sys/builder/main.rs
@@ -313,6 +313,7 @@ static mut AWS_LC_SYS_NO_PREFIX: bool = false;
 static mut AWS_LC_SYS_INTERNAL_BINDGEN: bool = false;
 static mut AWS_LC_SYS_EXTERNAL_BINDGEN: bool = false;
 static mut AWS_LC_SYS_NO_ASM: bool = false;
+static mut AWS_LC_SYS_PREBUILT_NASM: bool = false;

 fn initialize() {
     unsafe {
@@ -322,6 +323,7 @@ fn initialize() {
         AWS_LC_SYS_EXTERNAL_BINDGEN =
             env_var_to_bool("AWS_LC_SYS_EXTERNAL_BINDGEN").unwrap_or(false);
         AWS_LC_SYS_NO_ASM = env_var_to_bool("AWS_LC_SYS_NO_ASM").unwrap_or(false);
+        AWS_LC_SYS_PREBUILT_NASM = env_var_to_bool("AWS_LC_SYS_PREBUILT_NASM").unwrap_or(false);
     }

     if !is_external_bindgen() && (is_internal_bindgen() || !has_bindgen_feature()) {
@@ -369,6 +371,10 @@ fn is_no_asm() -> bool {
     unsafe { AWS_LC_SYS_NO_ASM }
 }

+fn is_prebuilt_nasm() -> bool {
+    unsafe { AWS_LC_SYS_PREBUILT_NASM }
+}
+
 fn has_bindgen_feature() -> bool {
     cfg!(feature = "bindgen")
 }
diff --git a/aws-lc-sys/builder/prebuilt-nasm.bat b/aws-lc-sys/builder/prebuilt-nasm.bat
new file mode 100644
index 0000000000..9c761db12a
--- /dev/null
+++ b/aws-lc-sys/builder/prebuilt-nasm.bat
@@ -0,0 +1,21 @@
+@echo off
+set "ScriptDir=%~dp0"
+set "ScriptDir=%ScriptDir:~0,-1%"
+:loop
+set "arg1=%~1"
+if "%arg1%"=="-o" goto end
+if "%arg1%"=="" goto failure
+shift
+goto loop
+:end
+shift
+set "path=%~1"
+for %%f in ("%path%") do set "filename=%%~nxf"
+copy "%ScriptDir%\prebuilt-nasm\%filename%" "%path%"
+exit 0
+
+:failure
+echo PATH: %path% 1>&2
+echo FILENAME: %filename% 1>&2
+echo ScriptDir: %ScriptDir% 1>&2
+exit 1
\ No newline at end of file
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aes128gcmsiv-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aes128gcmsiv-x86_64.obj
new file mode 100644
index 0000000000..3caa1c64f7
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aes128gcmsiv-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-avx512.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-avx512.obj
new file mode 100644
index 0000000000..99dff121d2
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-avx512.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-x86_64.obj
new file mode 100644
index 0000000000..a40c77f839
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-gcm-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-sha1-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha1-x86_64.obj
new file mode 100644
index 0000000000..9b14149bc8
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha1-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-sha256-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha256-x86_64.obj
new file mode 100644
index 0000000000..de492cd645
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-sha256-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-x86_64.obj
new file mode 100644
index 0000000000..77ef35b43f
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/aesni-xts-avx512.obj b/aws-lc-sys/builder/prebuilt-nasm/aesni-xts-avx512.obj
new file mode 100644
index 0000000000..45e257d9ff
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/aesni-xts-avx512.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/chacha-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/chacha-x86_64.obj
new file mode 100644
index 0000000000..37a378b223
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/chacha-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/chacha20_poly1305_x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/chacha20_poly1305_x86_64.obj
new file mode 100644
index 0000000000..05cee5a3d1
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/chacha20_poly1305_x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/ghash-ssse3-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/ghash-ssse3-x86_64.obj
new file mode 100644
index 0000000000..42566f60be
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/ghash-ssse3-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/ghash-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/ghash-x86_64.obj
new file mode 100644
index 0000000000..3706db4563
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/ghash-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/md5-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/md5-x86_64.obj
new file mode 100644
index 0000000000..6ebd3e7916
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/md5-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/p256-x86_64-asm.obj b/aws-lc-sys/builder/prebuilt-nasm/p256-x86_64-asm.obj
new file mode 100644
index 0000000000..ef2ab1e558
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/p256-x86_64-asm.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/p256_beeu-x86_64-asm.obj b/aws-lc-sys/builder/prebuilt-nasm/p256_beeu-x86_64-asm.obj
new file mode 100644
index 0000000000..98b6522f5a
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/p256_beeu-x86_64-asm.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/rdrand-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/rdrand-x86_64.obj
new file mode 100644
index 0000000000..25ecc304a0
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/rdrand-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/rsaz-avx2.obj b/aws-lc-sys/builder/prebuilt-nasm/rsaz-avx2.obj
new file mode 100644
index 0000000000..39d98ee7b7
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/rsaz-avx2.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/sha1-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/sha1-x86_64.obj
new file mode 100644
index 0000000000..28f049ba7f
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/sha1-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/sha256-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/sha256-x86_64.obj
new file mode 100644
index 0000000000..88fa74e3cb
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/sha256-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/sha512-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/sha512-x86_64.obj
new file mode 100644
index 0000000000..258d354f4e
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/sha512-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/trampoline-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/trampoline-x86_64.obj
new file mode 100644
index 0000000000..3370a1073f
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/trampoline-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/vpaes-x86_64.obj b/aws-lc-sys/builder/prebuilt-nasm/vpaes-x86_64.obj
new file mode 100644
index 0000000000..1e24b23b01
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/vpaes-x86_64.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont.obj b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont.obj
new file mode 100644
index 0000000000..5a841d3ee3
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont.obj differ
diff --git a/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont5.obj b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont5.obj
new file mode 100644
index 0000000000..135436db3b
Binary files /dev/null and b/aws-lc-sys/builder/prebuilt-nasm/x86_64-mont5.obj differ
@awakecoding
Copy link

@justsmth thanks for the detailed update. I've spent some more time on this today, hoping to fix the build issue on our side since the switch from ring-rs to aws-lc-rs in rustls. I spent a fair amount of time helping to get ring-rs fixed upstream for Windows on ARM in the past, and there may be some interesting strategies to reuse for build setup simplification.

I almost got a build setup working properly with the current release (0.19.0) used by rustls, the one remaining issue is the lack of proper support for RUSTFLAGS="-C target-feature=+crt-static" (MSVC static runtime linking) that doesn't seem to get propagated properly to the aws-lc-sys native component, causing a runtime linker conflict. I believe you may be trying to fix this as we speak, given you recent commits.

Let me summarize the steps I took to get the current version of aws-lc-rs to build locally with MSVC on Windows. In Visual Studio, I installed "MSVC v143 - VS 2022 C++ ARM64 build tools (v14,32 -17.2)", "MSVC v143 - VS 2022 C++ ARM64/ARM64EC build tools (latest)", "C++ ATL for latest v143 build tools (ARM64/ARM64EC)", "C++ Clang Compiler for Windows (17.0.3)" and "MSBuild support for LLVM (clang-cl) toolset". There's probably a few of those that aren't needed, but more testing would be required to find the minimum subset.

Install ninja, vswhere and nasm:

choco install ninja vswhere nasm

winget install Ninja-build.Ninja
winget install Microsoft.VisualStudio.Locator
winget install NASM.NASM

To get an easier Visual Studio Developer PowerShell environment, I use my own VsDevShell PowerShell module (much less painful to use than the one that comes with Visual Studio):

Install-Module VsDevShell -Force

Clone the current aws-lc-rs repository with the release tag for 0.19.0:

git clone git@github.com:aws/aws-lc-rs
cd aws-lc-rs
git submodule update --init
git checkout aws-lc-sys/v0.19.0

Add nasm to the PATH (not added by default, very annoying, even if it's in a very predictable install path):

$Env:PATH += ";C:\Program Files\NASM"

Set LIBCLANG_PATH to the one from Visual Studio, using vswhere.exe:

$VSINSTALLDIR = $(vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang -property installationPath)
$Env:LIBCLANG_PATH="$VSINSTALLDIR\VC\Tools\Llvm\x64\bin"

Enter an arm64 developer shell to get all the environment variables for the cmake Ninja generator to build C/C++ programs properly in Windows. Since clang-cl is installed and loaded automatically in the developer shell, it will likely pick it up as the C/C++ compiler, but it may also use it as its assembler program. For ring-rs, relying on clang for building C and assembly for ARM64 was just simpler due to limitations of the MSVC cl.exe and armasm64.exe.

Enter-VsDevShell arm64

Build aws-lc-sys in release for aarch64-pc-windows-msvc, with very verbose output so you can see the CMake commmands:

cargo build -p aws-lc-sys --release --target aarch64-pc-windows-msvc -vvv

To get to build to fail with the static crt issue, just set $Env:RUSTFLAGS="-C target-feature=+crt-static" before calling cargo build.

Can you give an update on the current status for crt-static support? Will it be fixed in the next release?

@Alovchin91
Copy link

I’ll be watching this.

@rami3l
Copy link
Author

rami3l commented Jul 17, 2024

@awakecoding crt-static has already been considered in the new CI tests, as discussed in #453 (comment).

@rami3l
Copy link
Author

rami3l commented Jul 17, 2024

I tested again in https://github.com/rust-lang/rustup/actions/runs/9967623316/job/27541588108 with the cargo patch set to eeac93b. The CI didn't pass completely but at least this issue regarding Windows ARM64 can be safely closed.

@justsmth thank you so much for your investigation and hard work so far! I'll see you again very soon in other follow-up issues 😶

@rami3l rami3l closed this as completed Jul 17, 2024
@justsmth
Copy link
Contributor

justsmth commented Jul 17, 2024

Can you give an update on the current status for crt-static support? Will it be fixed in the next release?

@awakecoding - Yeah, our latest changes on main have CI tests using /WX both with and w/o "crt-static".

      - name: Set RUSTFLAGS
        run: |
          if ('${{ matrix.crt_static }}' -eq '1') {
            echo "RUSTFLAGS=-Clink-arg=/WX -Ctarget-feature=+crt-static" | Out-File -FilePath $env:GITHUB_ENV -Append
          } else {
            echo "RUSTFLAGS=-Clink-arg=/WX" | Out-File -FilePath $env:GITHUB_ENV -Append
          }

Here's a CI workflow where it's being tested: https://github.com/aws/aws-lc-rs/actions/runs/9962674772/job/27527026533?pr=460

@awakecoding
Copy link

@justsmth do you build shared libraries or executables that link aws-lc-rs into it? MSVC linker errors due to a runtime mismatch will only cause issues then, so the current tests are probably not enough.

I managed to backport crt-static build fixed on 0.19.0, but they go beyond what's currently on the main branch, so I suspect the problem wasn't truly fixed, at least not with the Ninja generator. I've been patching CMake build systems for several years to inject annoying code to search and replace the /MD and /MT flags because they're getting set in the initial flags, and those passed through cmake parameters only get added, which still leads to a conflict. That's what I've been hitting locally.

CMake 3.15 added the CMAKE_MSVC_RUNTIME_LIBRARY option which takes a CMake generator expression to set the MSVC runtime properly for debug and release builds, but the current CMakeLists.txt uses cmake_minimum_required(VERSION 3.0) at the beginning, and it needs to be changed to 3.15 at a minimum for this to work. I added the following on my patched branch:

if target_os() == "windows" {
    // https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
    let is_crt_static = cargo_env("CARGO_CFG_TARGET_FEATURE").contains("crt-static");
    if is_crt_static {
        cmake_cfg.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>");
    } else {
        cmake_cfg.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
    }
    cmake_cfg.static_crt(is_crt_static); // not enough, but set it anyway
}

Yes, MSVC runtime linker options with CMake are a pain... I know. this is just the simplest solution to get things to build, otherwise a pre-3.15 cmake backport requires custom functions to modify all the flag variables and switch them based on a custom cmake option.

I then added this to my project Cargo.toml to patch aws-lc-sys 0.19.0 in my builds of sspi-rs:

[patch.crates-io]
aws-lc-sys = { git = "https://github.com/awakecoding/aws-lc-rs", branch = "v0.19.0-patched" }

and I finally have working builds again, with all the CI modifications for the environment setup. It's still going to be painful to build for local development now, but hopefully we can reduce reliance on certain things to be preconfigured, and add automatic detection of some tools in known install paths. I also noticed there might be some pre-generated object code options like what ring-rs does? This simplifies the build setup without an assembler installed.

For now, I suggest adding the building of an executable or shared library that links aws-lc-rs to properly test for MSVC runtime linker problems. Is this the case right now?

@rami3l
Copy link
Author

rami3l commented Jul 17, 2024

I suggest adding the building of an executable or shared library that links aws-lc-rs to properly test for MSVC runtime linker problems.

@awakecoding AFAIK the new CI is building test binaries (included in --all-targets) which is linked against the lib itself... Also that's how we were able to reproduce the problems encountered at Rustup in aws-lc-rs' own CI.

I suspect the problem wasn't truly fixed, at least not with the Ninja generator.

But ninja is no longer required for Windows ARM64 on master... I'm not sure whether we're on the same page?

@awakecoding
Copy link

awakecoding commented Jul 17, 2024

I suggest adding the building of an executable or shared library that links aws-lc-rs to properly test for MSVC runtime linker problems.

@awakecoding AFAIK the new CI is building test binaries (included in --all-targets) which is linked against the lib itself... Also that's how we were able to reproduce the problems encountered at Rustup in aws-lc-rs' own CI.

I suspect the problem wasn't truly fixed, at least not with the Ninja generator.

But ninja is no longer required for Windows ARM64 on master... I'm not sure whether we're on the same page?

yeah, that was my next question - I looked at the cmake-rs code and it handles the MSVC runtime linker options differently for the Visual Studio and Ninja cmake generators, so if it's working upstream with the Visual Studio generator, it means there's an issue with the Ninja generator support and how it was used with 0.19.0. I got something that works with 0.19.0 with my patch, just know about this limitation if you ever switch to Ninja again, or offer the option to use it instead of the Visual Studio generator. Even after aws-lc-sys 0.20.0 is released, we'll need to wait for Rustls to update, which is why backporting fixes to 0.19.0 was the best solution to get our sspi-rs builds back on track.

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