aws-samples / serverless-rust-demo

Sample serverless application written in Rust
MIT No Attribution
271 stars 22 forks source link

fix: switch to cross for cross-compilation #5

Closed nmoutschen closed 3 years ago

nmoutschen commented 3 years ago

Issue #, if available: https://github.com/aws-samples/serverless-rust-demo/issues/2

Description of changes:

Switch to cross for cross-compiling to aarch64-unknown-linux-gnu.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

nmoutschen commented 3 years ago

Hey @brainstorm ! Could you tell me if this PR solves the issue for you on an M1 mac?

I tried on an Intel Mac and Linux and it worked, but I don't have an M1 mac unfortunately.

brainstorm commented 3 years ago

Hey @nmoutschen, thanks for iterating on this!

Unfortunately it does not work on my M1:

% make build
cross build --release --target aarch64-unknown-linux-gnu
   Compiling regex v1.5.4
   Compiling regex-automata v0.1.10
   Compiling http-body v0.4.3
   Compiling ring v0.16.20
   Compiling parking_lot_core v0.8.5
   Compiling signal-hook-registry v1.4.0
   Compiling mio v0.7.13
   Compiling num_cpus v1.13.0
error: failed to run custom build command for `ring v0.16.20`

Caused by:
  process didn't exit successfully: `/Users/rvalls/dev/umccr/serverless-rust-demo/target/release/build/ring-5100f9369a354546/build-script-build` (exit status: 101)
  --- stdout
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-unknown-linux-gnu")
  HOST = Some("aarch64-apple-darwin")
  CC_aarch64-unknown-linux-gnu = None
  CC_aarch64_unknown_linux_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_aarch64-unknown-linux-gnu = None
  CFLAGS_aarch64_unknown_linux_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = None

  --- stderr
  running "aarch64-linux-gnu-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/Users/rvalls/dev/umccr/serverless-rust-demo/target/aarch64-unknown-linux-gnu/release/build/ring-5243877d4a8e9964/out/aesv8-armx-linux64.o" "/Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesv8-armx-linux64.S"
  thread 'main' panicked at 'failed to execute ["aarch64-linux-gnu-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-DNDEBUG" "-c" "-o/Users/rvalls/dev/umccr/serverless-rust-demo/target/aarch64-unknown-linux-gnu/release/build/ring-5243877d4a8e9964/out/aesv8-armx-linux64.o" "/Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesv8-armx-linux64.S"]: No such file or directory (os error 2)', /Users/rvalls/.cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:653:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
make: *** [build] Error 101
brainstorm commented 3 years ago

So I guess at this point it's either podman:

https://news.ycombinator.com/item?id=28429650

Or the older Docker workaround you pointed at:

https://github.community/t/why-is-docker-not-installed-on-macos/17017/7

I'd prefer to have it solved natively though (cargo build), but I get it can be tricky to fix up properly... happy to test out things you throw my way in any case ;)

ScriptSmith commented 3 years ago

Using cross works for me on archlinux.

I needed to install aarch64-linux-gnu-gcc to compile for arm, but then my OS had a too-recent version of glibc for al2:

/var/task/bootstrap: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by /var/task/bootstrap)
/var/task/bootstrap: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by /var/task/bootstrap)
/var/task/bootstrap: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by /var/task/bootstrap)

Building with cross worked & passed all the tests

nmoutschen commented 3 years ago

Thanks @ScriptSmith ! I'm going to merge this for now, but keep the issue on M1 macs open until I find a way to reproduce/explore this.