Skip to content

Commit d6084a3

Browse files
authored
Merge pull request #41 from aws-samples/zigbuild
chore: switch to zigbuild for cross compilation
2 parents 8659ab1 + fff440e commit d6084a3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ STACK_NAME ?= rust-products
22
FUNCTIONS := get-products get-product put-product delete-product dynamodb-streams
33

44
ARCH := aarch64-unknown-linux-gnu
5+
ARCH_SPLIT = $(subst -, ,$(ARCH))
56

67
.PHONY: build deploy tests
78

@@ -15,7 +16,10 @@ endif
1516
ifeq (,$(shell which cargo))
1617
$(error "Could not found Cargo, please install it")
1718
endif
18-
cargo install cross
19+
ifeq (,$(shell which zig))
20+
$(error "Could not found Zig compiler, please install it")
21+
endif
22+
cargo install cargo-zigbuild
1923
ifeq (,$(shell which sam))
2024
$(error "Could not found SAM CLI, please install it")
2125
endif
@@ -24,7 +28,14 @@ ifeq (,$(shell which artillery))
2428
endif
2529

2630
build:
27-
cross build --release --target $(ARCH)
31+
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))")
32+
@echo "Same host and target. Using native build"
33+
cargo build --release --target $(ARCH)
34+
else
35+
@echo "Different host and target. Using zigbuild"
36+
cargo zigbuild --release --target $(ARCH)
37+
endif
38+
2839
rm -rf ./build
2940
mkdir -p ./build
3041
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ This single crate will create [five different binaries](./src/bin), one for each
1515
### Requirements
1616

1717
* [Rust](https://www.rust-lang.org/) 1.56.0 or higher
18-
* [Cross](https://github.com/rust-embedded/cross) for cross-compilation to Arm64
18+
* [cargo-zigbuild](https://github.com/messense/cargo-zigbuild) and [Zig](https://ziglang.org/) for cross-compilation
19+
* [jq](https://stedolan.github.io/jq/) for tooling specific to this project
1920
* 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
2021
* [Artillery](https://artillery.io/) for load-testing the application
2122

0 commit comments

Comments
 (0)