From fff440e69927e3c3fc60e4897801fa6f72b36315 Mon Sep 17 00:00:00 2001 From: Nicolas Moutschen Date: Fri, 18 Feb 2022 09:12:41 +0100 Subject: [PATCH] chore: switch to zigbuild for cross compilation --- Makefile | 15 +++++++++++++-- README.md | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 60232c6..0dc03fe 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ STACK_NAME ?= rust-products FUNCTIONS := get-products get-product put-product delete-product dynamodb-streams ARCH := aarch64-unknown-linux-gnu +ARCH_SPLIT = $(subst -, ,$(ARCH)) .PHONY: build deploy tests @@ -15,7 +16,10 @@ endif ifeq (,$(shell which cargo)) $(error "Could not found Cargo, please install it") endif - cargo install cross +ifeq (,$(shell which zig)) + $(error "Could not found Zig compiler, please install it") +endif + cargo install cargo-zigbuild ifeq (,$(shell which sam)) $(error "Could not found SAM CLI, please install it") endif @@ -24,7 +28,14 @@ ifeq (,$(shell which artillery)) endif build: - cross build --release --target $(ARCH) +ifeq ("$(shell zig targets | jq -r .native.cpu.arch)-$(shell zig targets | jq -r .native.os)-$(shell zig targets | jq -r .native.abi)", "$(word 1,$(ARCH_SPLIT))-$(word 3,$(ARCH_SPLIT))-$(word 4,$(ARCH_SPLIT))") + @echo "Same host and target. Using native build" + cargo build --release --target $(ARCH) +else + @echo "Different host and target. Using zigbuild" + cargo zigbuild --release --target $(ARCH) +endif + rm -rf ./build mkdir -p ./build ${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function}) diff --git a/README.md b/README.md index f70b4d3..e2a1f65 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ This single crate will create [five different binaries](./src/bin), one for each ### Requirements * [Rust](https://www.rust-lang.org/) 1.56.0 or higher -* [Cross](https://github.com/rust-embedded/cross) for cross-compilation to Arm64 +* [cargo-zigbuild](https://github.com/messense/cargo-zigbuild) and [Zig](https://ziglang.org/) for cross-compilation +* [jq](https://stedolan.github.io/jq/) for tooling specific to this project * The [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) 1.33.0 or higher for deploying to the cloud * [Artillery](https://artillery.io/) for load-testing the application