Skip to content

Commit 22d9ec2

Browse files
authored
Merge pull request #403 from ymwjbxxq/ymwjbxxq-fix-rust-arm64-cross-compiler
Rust: align all rust examples to use zigbuild for cross compilation
2 parents bbccfe8 + def6872 commit 22d9ec2

File tree

13 files changed

+73
-13
lines changed

13 files changed

+73
-13
lines changed

apigw-http-api-lambda-rust/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
FUNCTIONS := handler
22
ARCH := aarch64-unknown-linux-gnu
3+
ARCH_SPLIT = $(subst -, ,$(ARCH))
34

45
build:
5-
cross build --release --target $(ARCH)
6+
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))")
7+
@echo "Same host and target. Using native build"
8+
cargo build --release --target $(ARCH)
9+
else
10+
@echo "Different host and target. Using zigbuild"
11+
cargo zigbuild --release --target $(ARCH)
12+
endif
13+
614
rm -rf ./build
715
mkdir -p ./build
816
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})

apigw-http-api-lambda-rust/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Important: this application uses various AWS services and there are costs associ
1212
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
1313
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
1414
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
* [Rust](https://www.rust-lang.org/) 1.56.0 or higher
16+
* [cargo-zigbuild](https://github.com/messense/cargo-zigbuild) and [Zig](https://ziglang.org/) for cross-compilation
1517

1618
## Deployment Instructions
1719

@@ -23,7 +25,7 @@ Important: this application uses various AWS services and there are costs associ
2325
```
2426
cd apigw-http-api-lambda-rust
2527
```
26-
3. Install dependencies and build (docker and cross build are required):
28+
3. Install dependencies and build:
2729
```
2830
make build
2931
```

lambda-s3-rust/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
FUNCTIONS := handler
22
ARCH := aarch64-unknown-linux-gnu
3+
ARCH_SPLIT = $(subst -, ,$(ARCH))
34

45
build:
5-
cross build --release --target $(ARCH)
6+
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))")
7+
@echo "Same host and target. Using native build"
8+
cargo build --release --target $(ARCH)
9+
else
10+
@echo "Different host and target. Using zigbuild"
11+
cargo zigbuild --release --target $(ARCH)
12+
endif
13+
614
rm -rf ./build
715
mkdir -p ./build
816
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})

lambda-s3-rust/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Important: this application uses various AWS services and there are costs associ
1212
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
1313
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
1414
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
* [Rust](https://www.rust-lang.org/) 1.56.0 or higher
16+
* [cargo-zigbuild](https://github.com/messense/cargo-zigbuild) and [Zig](https://ziglang.org/) for cross-compilation
1517

1618
## Deployment Instructions
1719

@@ -23,7 +25,7 @@ Important: this application uses various AWS services and there are costs associ
2325
```
2426
cd lambda-s3-rust
2527
```
26-
3. Install dependencies and build (docker and cross build are required):
28+
3. Install dependencies and build:
2729
```
2830
make build
2931
```

lambda-sfn-rust/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
FUNCTIONS := handler
22
ARCH := aarch64-unknown-linux-gnu
3+
ARCH_SPLIT = $(subst -, ,$(ARCH))
34

45
build:
5-
cross build --release --target $(ARCH)
6+
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))")
7+
@echo "Same host and target. Using native build"
8+
cargo build --release --target $(ARCH)
9+
else
10+
@echo "Different host and target. Using zigbuild"
11+
cargo zigbuild --release --target $(ARCH)
12+
endif
13+
614
rm -rf ./build
715
mkdir -p ./build
816
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})

lambda-sfn-rust/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Important: this application uses various AWS services and there are costs associ
1212
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
1313
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
1414
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
* [Rust](https://www.rust-lang.org/) 1.56.0 or higher
16+
* [cargo-zigbuild](https://github.com/messense/cargo-zigbuild) and [Zig](https://ziglang.org/) for cross-compilation
1517

1618
## Deployment Instructions
1719

@@ -23,7 +25,7 @@ Important: this application uses various AWS services and there are costs associ
2325
```
2426
cd lambda-sfn-rust
2527
```
26-
3. Install dependencies and build (docker and cross build are required):
28+
3. Install dependencies and build:
2729
```
2830
make build
2931
```

lambda-sqs-rust/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
FUNCTIONS := handler
22
ARCH := aarch64-unknown-linux-gnu
3+
ARCH_SPLIT = $(subst -, ,$(ARCH))
34

45
build:
5-
cross build --release --target $(ARCH)
6+
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))")
7+
@echo "Same host and target. Using native build"
8+
cargo build --release --target $(ARCH)
9+
else
10+
@echo "Different host and target. Using zigbuild"
11+
cargo zigbuild --release --target $(ARCH)
12+
endif
13+
614
rm -rf ./build
715
mkdir -p ./build
816
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})

lambda-sqs-rust/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Important: this application uses various AWS services and there are costs associ
1212
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
1313
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
1414
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
* [Rust](https://www.rust-lang.org/) 1.56.0 or higher
16+
* [cargo-zigbuild](https://github.com/messense/cargo-zigbuild) and [Zig](https://ziglang.org/) for cross-compilation
1517

1618
## Deployment Instructions
1719

@@ -23,7 +25,7 @@ Important: this application uses various AWS services and there are costs associ
2325
```
2426
cd lambda-sqs-rust
2527
```
26-
3. Install dependencies and build (docker and cross build are required):
28+
3. Install dependencies and build:
2729
```
2830
make build
2931
```

s3-eventbridge-direct-rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "sqs-lambda-rust"
2+
name = "s3-eventbridge-direct-rust"
33
version = "0.1.0"
44
edition = "2021"
55

s3-eventbridge-direct-rust/Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
FUNCTIONS := handler
22
ARCH := aarch64-unknown-linux-gnu
3+
ARCH_SPLIT = $(subst -, ,$(ARCH))
34

45
build:
5-
cross build --release --target $(ARCH)
6+
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))")
7+
@echo "Same host and target. Using native build"
8+
cargo build --release --target $(ARCH)
9+
else
10+
@echo "Different host and target. Using zigbuild"
11+
cargo zigbuild --release --target $(ARCH)
12+
endif
13+
614
rm -rf ./build
715
mkdir -p ./build
816
${MAKE} ${MAKEOPTS} $(foreach function,${FUNCTIONS}, build-${function})

0 commit comments

Comments
 (0)