Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
richarddavison committed Jan 26, 2024
1 parent 811a52f commit 04470bb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 80 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
arch:
required: true
type: string
release:
required: false
type: string

jobs:
build:
Expand Down Expand Up @@ -85,3 +88,25 @@ jobs:
qemu-user
make CURRENT_TARGET=aarch64-unknown-linux-gnu test-ci
- name: Build Linux binaries
if: inputs.release && inputs.platform == 'linux'
run: |
make llrt-lambda-${{ inputs.release }}.zip
make release-${{ inputs.release }}
- name: Build Darwin binaries
if: inputs.release && inputs.platform == 'darwin'
run: |
make llrt-darwin-${{ inputs.release }}.zip
- name: Upload artifacts
if: inputs.release
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ inputs.platform }}
path: |
*.zip
- name: Upload changelog
if: inputs.release && inputs.platform == 'linux' && inputs.arch == 'x86_64'
uses: actions/upload-artifact@v4
with:
name: changelog
path: CHANGELOG.md
51 changes: 8 additions & 43 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,33 @@ on:
- "v*.*.*"

jobs:
prebuild:
build:
strategy:
fail-fast: ${{ startsWith(github.ref, 'refs/tags/') }}
matrix:
include:
- os: ubuntu-latest
platform: linux
arch: x86_64
release: x64
- os: ubuntu-latest
platform: linux
arch: aarch64
release: arm64
- os: macos-latest
platform: darwin
arch: x86_64
release: x64
- os: macos-latest
platform: darwin
arch: aarch64
release: arm64
uses: ./.github/workflows/build.yml
with:
os: ${{ matrix.os }}
platform: ${{ matrix.platform }}
arch: ${{ matrix.arch }}
build:
needs:
- prebuild
strategy:
fail-fast: ${{ startsWith(github.ref, 'refs/tags/') }}
matrix:
include:
- os: ubuntu-latest
platform: linux
arch: x86_64
- os: ubuntu-latest
platform: linux
arch: aarch64
- os: macos-latest
platform: darwin
arch: x86_64
- os: macos-latest
platform: darwin
arch: aarch64
runs-on: ${{ matrix.os }}
steps:
- name: Build binaries
run: |
make release
- name: Build Lambda binaries
if: matrix.platform == 'linux'
run: |
make release-lambda
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.platform }}
path: |
*.zip
- name: Upload changelog
if: matrix.platform == 'linux' && matrix.arch == 'x86_64'
uses: actions/upload-artifact@v4
with:
name: changelog
path: CHANGELOG.md
release: ${{ matrix.release }}
release:
permissions:
contents: write
Expand All @@ -87,5 +52,5 @@ jobs:
./artifacts-linux/llrt-lambda-arm64.zip
./artifacts-linux/llrt-linux-x64.zip
./artifacts-linux/llrt-linux-arm64.zip
./artifacts-darwin/llrt-macos-x64.zip
./artifacts-darwin/llrt-macos-arm64.zip
./artifacts-darwin/llrt-darwin-x64.zip
./artifacts-darwin/llrt-darwin-arm64.zip
46 changes: 14 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TOOLCHAIN = +$(RUST_VERSION)
BUILD_ARG = $(TOOLCHAIN) build -r
BUILD_DIR = ./target/release
BUNDLE_DIR = bundle
ZSTD_LIB_ARGS = -j lib-nomt CC="$(CURDIR)/zigcc -s -O3 -flto" UNAME=Linux ZSTD_LIB_COMPRESSION=0 ZSTD_LIB_DICTBUILDER=0
ZSTD_LIB_ARGS = -j lib-nomt CC="$(CURDIR)/zigcc -s -O3 -flto" AR="zig ar" UNAME=Linux ZSTD_LIB_COMPRESSION=0 ZSTD_LIB_DICTBUILDER=0

TS_SOURCES = $(wildcard src/js/*.ts) $(wildcard src/js/@llrt/*.ts) $(wildcard tests/*.ts)
STD_JS_FILE = $(BUNDLE_DIR)/@llrt/std.js
Expand Down Expand Up @@ -50,28 +50,25 @@ CURRENT_TARGET ?= $(TARGET_$(DETECTED_OS)_$(ARCH))

export COMPILE_TARGET = $(CURRENT_TARGET)

lambda-all: clean-js | libs $(RELEASE_ZIPS)
release-all: clean-js | lambda-all llrt-linux-x64.zip llrt-linux-arm64.zip llrt-darwin-x64.zip llrt-darwin-arm64.zip
lambda-all: libs $(RELEASE_ZIPS)
release-all: | lambda-all llrt-linux-x64.zip llrt-linux-arm64.zip llrt-darwin-x64.zip llrt-darwin-arm64.zip
release: llrt-$(DETECTED_OS)-$(ARCH).zip
release-linux: | lambda-all llrt-linux-x64.zip llrt-linux-arm64.zip
release-darwin: | llrt-darwin-x64.zip llrt-darwin-arm64.zip

release-lambda: clean-js | libs-$(ARCH) $(LAMBDA_PREFIX)-$(DETECTED_OS)-$(ARCH).zip
release: clean-js | llrt-$(DETECTED_OS)-$(ARCH).zip

release-linux: clean-js | lambda-all llrt-linux-x64.zip llrt-linux-arm64.zip
release-darwin: clean-js | llrt-darwin-x64.zip llrt-darwin-arm64.zip

llrt-darwin-x64.zip: js
llrt-darwin-x64.zip: | clean-js js
cargo $(BUILD_ARG) --target $(TARGET_darwin_x86_64)
zip -j $@ target/$(TARGET_darwin_x86_64)/release/llrt

llrt-darwin-arm64.zip: js
llrt-darwin-arm64.zip: | clean-js js
cargo $(BUILD_ARG) --target $(TARGET_darwin_arm64)
zip -j $@ target/$(TARGET_darwin_arm64)/release/llrt

llrt-linux-x64.zip: js
llrt-linux-x64.zip: | clean-js js
cargo $(BUILD_ARG) --target $(TARGET_linux_x86_64)
zip -j $@ target/$(TARGET_linux_x86_64)/release/llrt

llrt-linux-arm64.zip: js
llrt-linux-arm64.zip: | clean-js js
cargo $(BUILD_ARG) --target $(TARGET_linux_arm64)
zip -j $@ target/$(TARGET_linux_arm64)/release/llrt

Expand All @@ -80,7 +77,7 @@ release-${1}: js
COMPILE_TARGET=$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1})) cargo $$(BUILD_ARG) --target $$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1})) --features lambda -vv
./pack target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/llrt target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap
@rm -rf llrt-lambda-${1}.zip
zip -j llrt-lambda-${1}.zip target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap index.mjs
zip -j llrt-lambda-${1}.zip target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap

llrt-lambda-${1}: release-${1}
endef
Expand Down Expand Up @@ -115,18 +112,11 @@ js: $(STD_JS_FILE)
bundle/%.js: $(TS_SOURCES)
node build.mjs

patch:
cargo clean -p rquickjs-sys
cargo patch

fix:
cargo fix --allow-dirty
cargo clippy --fix --allow-dirty
cargo fmt

linux-flame: js
cargo build --profile=flame --target $(TARGET_linux_x86_64)

bloat: js
cargo build --profile=flame --target $(TARGET_linux_x86_64)
cargo bloat --profile=flame --crates
Expand All @@ -136,20 +126,12 @@ run: export AWS_LAMBDA_FUNCTION_MEMORY_SIZE = 1
run: export AWS_LAMBDA_FUNCTION_VERSION = 1
run: export AWS_LAMBDA_RUNTIME_API = localhost:3000
run: export _EXIT_ITERATIONS = 1
run: export AWS_REGION=eu-north-1
run: export TABLE_NAME=quickjs-table
run: export BUCKET_NAME=llrt-demo-bucket2
run: export JS_MINIFY = 0
run: export RUST_LOG = llrt=trace
run: export _HANDLER = index.handler
run: js
run: | clean-js js
cargo run -r -vv

run-js: export _HANDLER = index.handler
run-js:
touch build.rs
cargo run

run-release: export _HANDLER = fixtures/local.handler
run-release: js
cargo build
Expand Down Expand Up @@ -193,13 +175,13 @@ lib/zstd.h:
lib/arm64/libzstd.a:
mkdir -p $(dir $@)
rm -f zstd/lib/-.o
cd zstd/lib && make clean && COMPILE_TARGET=$(TARGET_linux_arm64) make $(ZSTD_LIB_ARGS)
cd zstd/lib && make clean && COMPILE_TARGET="aarch64-unknown-linux-musl" make $(ZSTD_LIB_ARGS)
cp zstd/lib/libzstd.a $@

lib/x64/libzstd.a:
mkdir -p $(dir $@)
rm -f zstd/lib/-.o
cd zstd/lib && make clean && COMPILE_TARGET=$(TARGET_linux_x86_64) make $(ZSTD_LIB_ARGS)
cd zstd/lib && make clean && COMPILE_TARGET="x86_64-unknown-linux-musl" make $(ZSTD_LIB_ARGS)
cp zstd/lib/libzstd.a $@

bench:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Install dependencies
# MacOS
brew install zig make zstd node corepack

# Ubuntu x
# Ubuntu
sudo apt -y install make zstd gcc \
libc6-arm64-cross \
libc6-dev-arm64-cross \
Expand Down
6 changes: 3 additions & 3 deletions pack
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fi
arch_hex=$(hexdump -s 18 -n 1 -e '"%02x"' $srcfile)

if [[ "$arch_hex" == "3e" ]]; then
target="x86_64-linux-gnu"
target="x86_64-linux-musl"
arch="x64"
elif [[ "$arch_hex" == "b7" ]]; then
target="aarch64-linux-gnu"
target="aarch64-linux-musl"
arch="arm64"
else
echo "The binary is not an ARM64 or X86_64 ELF executable"
Expand Down Expand Up @@ -97,7 +97,7 @@ echo "Compiling..."

original_size=$(du -h $srcfile | cut -f1)

zig cc -target $target -Wno-null-character -std=c99 -Wall -O3 -flto -s ${temp_folder}/main.c -o $dstfile -Ilib -Llib/${arch} -Wl,-Bstatic -lzstd -Wl,-Bdynamic -lpthread -lrt -lc
zig cc -target $target -Wno-null-character -std=c99 -Wall -O3 -flto -s ${temp_folder}/main.c -o $dstfile -Ilib -Llib/${arch} -static -lzstd

new_size=$(du -h $dstfile | cut -f1)

Expand Down
2 changes: 1 addition & 1 deletion tests/compile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("llrt compile", async () => {
assert.strictEqual(runResult.status, 0);
});

it.only("can compile and run throws", async () => {
it("can compile and run throws", async () => {
const tmpOutput = `${tmpDir}/throws.lrt`;

const compileResult = await compile("fixtures/throw.js", tmpOutput);
Expand Down

0 comments on commit 04470bb

Please sign in to comment.