Repository: aws/aws-lc-rs (language: rust)

Issue:
x86_64-pc-windows-gnu build failed
### Problem:

```
Copying platform assembly files from /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.17.0/aws-lc/generated-src/win-x86_64/crypto/ to /target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build/aws-lc/crypto
  /target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build/aws-lc/crypto/fipsmodule/aesni-gcm-avx512.asm:10: fatal: unable to open include file `openssl/boringssl_prefix_symbols_nasm.inc'
```

It could be reproduced in this project: https://github.com/shadowsocks/shadowsocks-rust by running:

```
cross build --release --target x86_64-pc-windows-gnu --features "full"
```

#### Relevant details
AWS-LC for Rust versions or commit: (crates.io aws-lc-sys v0.17.0)

System information: for linux, below info can be collected by running `uname -srvmp`
 * CPU architecture: x86_64
 * CPU name: Unknown
 * OS: Windows

Build log:
```text
   Compiling windows_x86_64_gnu v0.52.5
   Compiling windows_x86_64_gnu v0.48.5
   Compiling typenum v1.17.0
   Compiling generic-array v0.14.7
   Compiling ring v0.17.8
   Compiling winapi-x86_64-pc-windows-gnu v0.4.0
   Compiling futures-util v0.3.30
   Compiling der v0.7.9
   Compiling aws-lc-sys v0.17.0
   Compiling rand_chacha v0.3.1
   Compiling rustls-pki-types v1.7.0
   Compiling ff v0.13.0
   Compiling byteorder v1.5.0
   Compiling windows-targets v0.52.5
   Compiling windows-targets v0.48.5
   Compiling winapi v0.3.9
   Compiling base16ct v0.2.0
   Compiling rand v0.8.5
   Compiling windows-sys v0.52.0
   Compiling windows-sys v0.48.0
   Compiling parking_lot_core v0.9.10
   Compiling group v0.13.0
   Compiling opaque-debug v0.3.1
   Compiling mirai-annotations v1.12.0
   Compiling parking_lot v0.12.3
   Compiling syn v1.0.109
   Compiling ring v0.16.20
   Compiling unicode-normalization v0.1.23
   Compiling http v1.1.0
   Compiling signature v2.2.0
   Compiling unicode-bidi v0.3.15
   Compiling spin v0.5.2
   Compiling untrusted v0.7.1
   Compiling percent-encoding v2.3.1
   Compiling rustls v0.21.12
   Compiling ryu v1.0.18
   Compiling crossbeam-utils v0.8.20
   Compiling form_urlencoded v1.2.1
   Compiling futures-executor v0.3.30
   Compiling pin-project v1.1.5
   Compiling http v0.2.12
   Compiling rustc-hash v1.1.0
   Compiling httparse v1.8.0
   Compiling zstd-sys v1.6.2+zstd.1.5.1
   Compiling futures v0.3.30
   Compiling http-body v1.0.0
   Compiling idna v0.5.0
   Compiling fastrand v1.9.0
   Compiling ipnet v2.9.0
   Compiling try-lock v0.2.5
   Compiling rustls-webpki v0.101.7
   Compiling sct v0.7.1
   Compiling base64 v0.21.7
   Compiling atomic-waker v1.1.2
   Compiling serde_json v1.0.117
   Compiling want v0.3.1
   Compiling rustls-pemfile v1.0.4
   Compiling url v2.5.0
   Compiling socket2 v0.5.7
   Compiling schannel v0.1.23
   Compiling winapi-util v0.1.8
   Compiling num-traits v0.2.19
   Compiling spki v0.7.3
   Compiling mio v0.8.11
   Compiling quinn-udp v0.4.1
   Compiling match_cfg v0.1.0
   Compiling ipconfig v0.3.2
   Compiling arrayvec v0.7.4
   Compiling base64 v0.22.1
   Compiling powerfmt v0.2.0
   Compiling httpdate v1.0.3
   Compiling rustls v0.22.4
   Compiling tokio v1.37.0
   Compiling radium v0.7.0
   Compiling deranged v0.3.11
   Compiling quinn-proto v0.10.6
   Compiling parking_lot_core v0.8.6
   Compiling pkcs8 v0.10.2
   Compiling hostname v0.3.1
   Compiling blake3 v1.5.1
   Compiling winreg v0.50.0
   Compiling rustls-native-certs v0.6.3
   Compiling same-file v1.0.6
   Compiling idna v0.4.0
   Compiling ed25519 v2.2.3
   Compiling windows-core v0.51.1
   Compiling aho-corasick v1.1.3
   Compiling instant v0.1.13
   Compiling linked-hash-map v0.5.6
   Compiling tower-service v0.3.2
   Compiling c2rust-bitfields-derive v0.18.0
   Compiling num-conv v0.1.0
   Compiling tap v1.0.1
   Compiling widestring v1.1.0
   Compiling utf8parse v0.2.1
   Compiling regex-syntax v0.8.3
   Compiling constant_time_eq v0.3.0
The following warnings were emitted during compilation:

warning: aws-lc-sys@0.17.0: Generating bindings - external bindgen. Platform: x86_64-pc-windows-gnu

error: failed to run custom build command for `aws-lc-sys v0.17.0`

Caused by:
  process didn't exit successfully: `/target/debug/build/aws-lc-sys-9800ca95c1e3d479/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_PREFIX
  cargo:rerun-if-env-changed=AWS_LC_SYS_INTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_EXTERNAL_BINDGEN
  cargo:rerun-if-env-changed=AWS_LC_SYS_NO_ASM
  cargo:rerun-if-env-changed=AWS_LC_SYS_CMAKE_BUILDER
  cargo:rerun-if-env-changed=AWS_LC_SYS_STATIC
  cargo:warning=Generating bindings - external bindgen. Platform: x86_64-pc-windows-gnu
  cargo:rerun-if-env-changed=AWS_LC_SYS_INCLUDES
  cargo:rustc-cfg=use_bindgen_generated
  cargo:rerun-if-env-changed=AWS_LC_SYS_STATIC
  CMAKE_TOOLCHAIN_FILE_x86_64-pc-windows-gnu = None
  CMAKE_TOOLCHAIN_FILE_x86_64_pc_windows_gnu = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_x86_64-pc-windows-gnu = None
  CMAKE_GENERATOR_x86_64_pc_windows_gnu = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_x86_64-pc-windows-gnu = None
  CMAKE_PREFIX_PATH_x86_64_pc_windows_gnu = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_x86_64-pc-windows-gnu = None
  CMAKE_x86_64_pc_windows_gnu = None
  TARGET_CMAKE = None
  CMAKE = Some("cmake")
  running: cd "/target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build" && CMAKE_PREFIX_PATH="" "cmake" "/cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.17.0" "-DBUILD_SHARED_LIBS=0" "-DCMAKE_BUILD_TYPE=debug" "-DBORINGSSL_PREFIX=aws_lc_0_17_0_" "-DBORINGSSL_PREFIX_HEADERS=/cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.17.0/generated-include" "-DBUILD_TESTING=OFF" "-DBUILD_LIBSSL=OFF" "-DDISABLE_PERL=ON" "-DDISABLE_GO=ON" "-DCMAKE_SYSTEM_NAME=Windows" "-DCMAKE_SYSTEM_PROCESSOR=AMD64" "-DCMAKE_INSTALL_PREFIX=/target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out" "-DCMAKE_C_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_C_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc-posix" "-DCMAKE_CXX_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_CXX_COMPILER=/usr/bin/x86_64-w64-mingw32-g++-posix" "-DCMAKE_ASM_FLAGS= -ffunction-sections -fdata-sections -m64" "-DCMAKE_ASM_COMPILER=/usr/bin/x86_64-w64-mingw32-gcc-posix" "--no-warn-unused-cli"
  Not searching for unused variables given on the command line.
  -- The C compiler identification is GNU 7.3.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc-posix - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- Go not found. Disabling some code generation and using pre-generated code in generated-src/
  -- Perl not found. Disabling some code generation and using pre-generated code in generated-src/
  -- stdalign_check.c probe is positive, enabling AWS_LC_STDALIGN_AVAILABLE
  -- builtin_swap_check.c probe is positive, enabling AWS_LC_BUILTIN_SWAP_SUPPORTED
  -- The ASM_NASM compiler identification is NASM
  -- Found assembler: /usr/bin/nasm
  -- Looking for pthread.h
  -- Looking for pthread.h - found
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
  -- Found Threads: TRUE
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build
  running: cd "/target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build" && MAKEFLAGS="-j --jobserver-fds=8,9 --jobserver-auth=8,9" "cmake" "--build" "." "--target" "install" "--config" "Debug"
  [  0%] Built target boringssl_prefix_symbols
  [  1%] Building C object aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/bcm.c.obj
  [  1%] Building C object aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/fips_shared_support.c.obj
  [  2%] Building C object aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/cpucap/cpucap.c.obj
  [  2%] Building ASM_NASM object aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/aesni-gcm-avx512.asm.obj
  aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/build.make:120: recipe for target 'aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/aesni-gcm-avx512.asm.obj' failed
  CMakeFiles/Makefile2:257: recipe for target 'aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/all' failed
  Makefile:135: recipe for target 'all' failed

  --- stderr
  Copying platform assembly files from /cargo/registry/src/index.crates.io-6f17d22bba15001f/aws-lc-sys-0.17.0/aws-lc/generated-src/win-x86_64/crypto/ to /target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build/aws-lc/crypto
  /target/x86_64-pc-windows-gnu/debug/build/aws-lc-sys-156e9005524d4eed/out/build/aws-lc/crypto/fipsmodule/aesni-gcm-avx512.asm:10: fatal: unable to open include file `openssl/boringssl_prefix_symbols_nasm.inc'
  make[2]: *** [aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/aesni-gcm-avx512.asm.obj] Error 1
  make[1]: *** [aws-lc/crypto/fipsmodule/CMakeFiles/fipsmodule.dir/all] Error 2
  make: *** [all] Error 2
  thread 'main' panicked at /cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:

  command did not execute successfully, got: exit status: 2

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
```



Discussion / hints:
I'm unable to reproduce the error you're reporting using using the aws-lc-rs repo. I believe the problem related to the `Cross.toml` configuration that [you have here](https://github.com/shadowsocks/shadowsocks-rust/blob/7de93f78d6a01a80e5a0bd98929161005abac1d9/Cross.toml).

For reference, you can see the configuration that we use for Cross [here](https://github.com/aws/aws-lc-rs/blob/main/Cross.toml), which extends the configuration from our [Cross Dockerfile](https://github.com/aws/aws-lc-rs/blob/main/docker/linux-cross/Dockerfile).

It's not clear to me what a few of the steps in your configuration are attempting, but I suspect your configuration could be much simpler. Possibly something like: 
```
[build]
pre-build = [
  "apt-get install --assume-yes --no-install-recommends build-essential cmake nasm clang",
  "cargo install --force --locked bindgen-cli"
]
```
 
EDIT:
I experimented more with this. The `"cargo install --force --locked bindgen-cli"` doesn't work the way I'd expect, which likely explains the "rustup" commands you were using in your `Cross.toml`. I'll see if I can find a better solution.

Yes, there is no `cargo` in the base image. So I have to install one.

The [Dockerfile](https://github.com/aws/aws-lc-rs/blob/main/docker/linux-cross/Dockerfile) in this repo, installs `build-essential cmake golang-go`, and [Cross.toml](https://github.com/aws/aws-lc-rs/blob/main/Cross.toml) also installs `nasm clang wget` and also a `winehq-stable`.

Comparing to my own Cross.toml, I only installed `build-essential cmake nasm clang`, the missing one are `golang-go winehq-stable`. Do they necessary while building `aws-lc`?

Fix patch:
diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml
index f2179734711..4ab4dcdb617 100644
--- a/.github/workflows/cross.yml
+++ b/.github/workflows/cross.yml
@@ -28,20 +28,21 @@ jobs:
       matrix:
         os: [ ubuntu-22.04 ]
         target:
-          - arm-unknown-linux-gnueabihf
+          - aarch64-linux-android
           - aarch64-unknown-linux-gnu
-          - i686-unknown-linux-gnu
-          - powerpc64le-unknown-linux-gnu
-          - riscv64gc-unknown-linux-gnu
+          - aarch64-unknown-linux-musl
           - arm-linux-androideabi
+          - arm-unknown-linux-gnueabihf
           - armv7-linux-androideabi
-          - aarch64-linux-android
-          - powerpc64-unknown-linux-gnu
+          - armv7-unknown-linux-gnueabihf
+          - i686-unknown-linux-gnu
           - powerpc-unknown-linux-gnu
-          - x86_64-unknown-linux-musl
-          - aarch64-unknown-linux-musl
+          - powerpc64-unknown-linux-gnu
+          - powerpc64le-unknown-linux-gnu
+          - riscv64gc-unknown-linux-gnu
           - s390x-unknown-linux-gnu
           - x86_64-pc-windows-gnu
+          - x86_64-unknown-linux-musl
     steps:
       - uses: actions/checkout@v3
         with:
@@ -62,11 +63,10 @@ jobs:
         run: |
           cargo update
           cargo update -p clap --precise 4.4.18
-      - name: Cross-compilation
-        if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' || matrix.target == 'i686-unknown-linux-gnu' || matrix.target == 'x86_64-unknown-linux-musl' || matrix.target == 'aarch64-unknown-linux-musl'}}
-        run: cross test -p aws-lc-rs --features unstable --target ${{ matrix.target }}
-      - name: Cross-compilation w/ bindgen
-        run: cross test -p aws-lc-rs --release --features bindgen,unstable --target ${{ matrix.target }}
+      - name: Cross-compilation (build debug)
+        run: cross build -p aws-lc-rs --features unstable --target ${{ matrix.target }}
+      - name: Cross-compilation (test release)
+        run: cross test -p aws-lc-rs --release --features unstable --target ${{ matrix.target }}
 
   aws-lc-rs-ios-aarch64:
     if: github.repository_owner == 'aws'
diff --git a/Cross.toml b/Cross.toml
index bfbfc256e3e..027a609beea 100644
--- a/Cross.toml
+++ b/Cross.toml
@@ -1,12 +1,23 @@
 [build]
 dockerfile = "./docker/linux-cross/Dockerfile"
+pre-build = [
+    "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable",
+    ". $HOME/.cargo/env",
+    "cargo install --force --locked bindgen-cli && mv $HOME/.cargo/bin/bindgen /usr/bin",
+    "rm -rf $HOME/.cargo"
+]
+
 
 [target.x86_64-pc-windows-gnu]
 pre-build = [
-    "apt-get update && apt-get install --assume-yes nasm clang wget",
+    "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable",
+    ". $HOME/.cargo/env",
+    "cargo install --force --locked bindgen-cli && mv $HOME/.cargo/bin/bindgen /usr/bin",
+    "rm -rf $HOME/.cargo",
+    "apt-get update && apt-get install --assume-yes nasm wget",
     "mkdir -pm755 /etc/apt/keyrings",
     "wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources",
-    "apt install --assume-yes --install-recommends winehq-stable"
+    "apt install --assume-yes --install-recommends winehq-stable",
 ]
 
 [build.env]
diff --git a/docker/linux-cross/Dockerfile b/docker/linux-cross/Dockerfile
index cf03dbd7a8a..d25fc4eefa2 100644
--- a/docker/linux-cross/Dockerfile
+++ b/docker/linux-cross/Dockerfile
@@ -7,7 +7,7 @@ RUN apt-get update && \
     apt-get install --assume-yes --no-install-recommends  software-properties-common && \
     add-apt-repository --yes ppa:longsleep/golang-backports && \
     apt-get update && \
-    apt-get install --assume-yes --no-install-recommends build-essential cmake golang-go && \
+    apt-get install --assume-yes --no-install-recommends build-essential cmake golang-go clang && \
     git config --global --add safe.directory '*' && \
     rm -rf /tmp/*
 


Test patch: