Skip to content

Commit e87a7ae

Browse files
Use zig wrapper for compilation
1 parent e230c65 commit e87a7ae

File tree

6 files changed

+49
-25
lines changed

6 files changed

+49
-25
lines changed

.cargo/config.toml

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
[target.aarch64-unknown-linux-musl]
2+
rustflags = [
3+
"-Zpre-link-args=-target aarch64-linux-musl",
4+
"-Ctarget-feature=+lse,+crt-static",
5+
"-Ctarget-cpu=neoverse-n1",
6+
]
7+
linker = "./zigcc"
8+
ar = "zig ar"
9+
10+
[target.x86_64-unknown-linux-musl]
11+
rustflags = [
12+
"-Zpre-link-args=-target x86_64-linux-musl",
13+
"-Ctarget-feature=+crt-static",
14+
]
15+
linker = "./zigcc"
16+
ar = "zig ar"
17+
118
[unstable]
219
build-std = ["core", "compiler_builtins", "alloc", "std", "panic_abort"]
320
build-std-features = ["panic_immediate_abort"]
421

5-
# [target.aarch64-unknown-linux-musl]
6-
# rustflags = ["-Ctarget-feature=+lse,+crt-static", "-Ctarget-cpu=neoverse-n1"]
22+
[env]
23+
CC_aarch64_unknown_linux_musl = "zig cc -target aarch64-linux-musl"
24+
CXX_aarch64_unknown_linux_musl = "zig cc -target aarch64-linux-musl"
25+
CC_x86_64_unknown_linux_musl = "zig cc -target x86_64-linux-musl"
26+
CXX_x86_64_unknown_linux_musl = "zig cc -target x86_64-linux-musl"

.github/workflows/build.yml

+12-15
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,18 @@ jobs:
5656
uses: dtolnay/rust-toolchain@v1
5757
with:
5858
toolchain: nightly
59-
# - name: Cargo cache
60-
# uses: actions/cache@v4
61-
# continue-on-error: false
62-
# with:
63-
# path: |
64-
# ~/.cargo/bin/
65-
# ~/.cargo/registry/index/
66-
# ~/.cargo/registry/cache/
67-
# ~/.cargo/git/db/
68-
# target/
69-
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
70-
# restore-keys: ${{ runner.os }}-cargo-
71-
- name: Install cargo-zigbuild
72-
run: |
73-
cargo install cargo-zigbuild || true
59+
- name: Cargo cache
60+
uses: actions/cache@v4
61+
continue-on-error: false
62+
with:
63+
path: |
64+
~/.cargo/bin/
65+
~/.cargo/registry/index/
66+
~/.cargo/registry/cache/
67+
~/.cargo/git/db/
68+
target/
69+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
70+
restore-keys: ${{ runner.os }}-cargo-
7471
- name: Run tests
7572
if: inputs.arch != 'aarch64' || inputs.platform != 'linux'
7673
run: |

Makefile

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ TARGET_darwin_x86_64 = x86_64-apple-darwin
44
TARGET_darwin_arm64 = aarch64-apple-darwin
55
RUST_VERSION = nightly
66
TOOLCHAIN = +$(RUST_VERSION)
7-
ZIGBUILD_ARG = $(TOOLCHAIN) zigbuild -r
87
BUILD_ARG = $(TOOLCHAIN) build -r
98
BUILD_DIR = ./target/release
109
BUNDLE_DIR = bundle
1110
ZSTD_LIB_ARGS = -j lib-nomt UNAME=Linux ZSTD_LIB_COMPRESSION=0 ZSTD_LIB_DICTBUILDER=0 AR="zig ar"
1211
ZSTD_LIB_CC_ARGS = -s -O3 -flto
1312
ZSTD_LIB_CC_arm64 = CC="zig cc -target aarch64-linux-musl $(ZSTD_LIB_CC_ARGS)"
1413
ZSTD_LIB_CC_x64 = CC="zig cc -target aarch64-linux-musl $(ZSTD_LIB_CC_ARGS)"
15-
CARGO_TEST_CMD = cargo-zigbuild
1614

1715
TS_SOURCES = $(wildcard src/js/*.ts) $(wildcard src/js/@llrt/*.ts) $(wildcard tests/*.ts)
1816
STD_JS_FILE = $(BUNDLE_DIR)/@llrt/std.js
@@ -54,16 +52,16 @@ llrt-darwin-arm64.zip: | clean-js js
5452
zip -j $@ target/$(TARGET_darwin_arm64)/release/llrt
5553

5654
llrt-linux-x64.zip: | clean-js js
57-
cargo $(ZIGBUILD_ARG) --target $(TARGET_linux_x86_64)
55+
cargo $(BUILD_ARG) --target $(TARGET_linux_x86_64)
5856
zip -j $@ target/$(TARGET_linux_x86_64)/release/llrt
5957

6058
llrt-linux-arm64.zip: | clean-js js
61-
cargo $(ZIGBUILD_ARG) --target $(TARGET_linux_arm64)
59+
cargo $(BUILD_ARG) --target $(TARGET_linux_arm64)
6260
zip -j $@ target/$(TARGET_linux_arm64)/release/llrt
6361

6462
define release_template
6563
release-${1}: | clean-js js
66-
cargo $$(ZIGBUILD_ARG) --target $$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1})) --features lambda -vv
64+
cargo $$(BUILD_ARG) --target $$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1})) --features lambda -vv
6765
./pack target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/llrt target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap
6866
@rm -rf llrt-lambda-${1}.zip
6967
zip -j llrt-lambda-${1}.zip target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap index.mjs

example/functions/src/ssr.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ const assetResponse = async (path: string) => {
147147
};
148148

149149
export const handler = async (event: any) => {
150-
const { method, path: eventPath } = event?.requestContext?.http || {};
150+
const { method = "GET", path: eventPath = "/" } =
151+
event?.requestContext?.http || {};
151152

152153
try {
153154
const reqSegments: string[] = (eventPath as string)

src/vm.rs

-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,6 @@ fn json_parse_string<'js>(ctx: Ctx<'js>, value: Value<'js>) -> Result<Value<'js>
482482
}
483483

484484
fn run_gc(ctx: Ctx<'_>) {
485-
println!("ALLOCATED: {:?}", USED_MEM.load(Ordering::Relaxed));
486-
487485
if USED_MEM.load(Ordering::Relaxed) < *GC_THRESHOLD {
488486
return;
489487
}

zigcc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
set -e
3+
4+
new_array=()
5+
for value in "$@"
6+
do
7+
[[ $value != *self-contained/*crt* ]] && new_array+=($value)
8+
done
9+
10+
zig cc "${new_array[@]}"

0 commit comments

Comments
 (0)