move cross target testing into zig build test
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 2m58s

This commit is contained in:
Emil Lerch 2024-01-09 14:28:20 -08:00
parent 4c987d0959
commit dd4935b5e5
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 79 additions and 42 deletions

View File

@ -19,15 +19,16 @@ jobs:
#
# However, arm64/linux isn't quite fully tier 1 yet, so this is more of a
# TODO: https://github.com/ziglang/zig/issues/2443
- run: wget -q https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz
- run: tar x -C /usr/local -f zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz
- run: ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig
- run: curl https://wasmtime.dev/install.sh -sSf | bash
- run: zig build test
- run: zig build test -Dtarget=arm-linux # we want to know we can build for 32 bit
# - run: PATH=${HOME}/.wasmtime/bin:${PATH} zig build test -Dtarget=wasm32-wasi -fwasmtime # downstream needs this for CF workers
- run: zig build test -Dtarget=wasm32-wasi # downstream needs this for CF workers
# - run: zig build test -Dx86_64-windows # windows needs changes for env vars
- name: Install Zig
run: |
wget -q https://ziglang.org/download/${ZIG_VERSION}/zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz
tar x -C /usr/local -f zig-linux-${ARCH}-${ZIG_VERSION}.tar.xz
ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig
- name: Install wasmtime
run: curl https://wasmtime.dev/install.sh -sSf | bash
- name: Run tests
run: zig build test
# - run: PATH=${HOME}/.wasmtime/bin:${PATH} zig build test -fwasmtime # downstream needs this for CF workers
- name: Notify
uses: https://git.lerch.org/lobo/action-notify-ntfy@v2
if: always()

102
build.zig
View File

@ -1,5 +1,38 @@
const std = @import("std");
const test_targets = [_]std.zig.CrossTarget{
.{}, // native
.{
.cpu_arch = .x86_64,
.os_tag = .linux,
},
.{
.cpu_arch = .aarch64,
.os_tag = .linux,
},
.{
.cpu_arch = .arm,
.os_tag = .linux,
},
// Windows needs to avoid std.os.getenv - we'll wait until this is needed
// .{
// .cpu_arch = .x86_64,
// .os_tag = .windows,
// },
// I don't have a good way to test these
// .{
// .cpu_arch = .aarch64,
// .os_tag = .macos,
// },
// .{
// .cpu_arch = .x86_64,
// .os_tag = .macos,
// },
.{
.cpu_arch = .wasm32,
.os_tag = .wasi,
},
};
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
@ -32,40 +65,43 @@ pub fn build(b: *std.Build) !void {
// running `zig build`).
b.installArtifact(lib);
// Creates steps for unit testing. This only builds the test executable
// but does not run it.
const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" },
.target = target,
.optimize = optimize,
});
_ = try universal_lambda.addModules(b, exe_tests);
var run_exe_tests = b.addRunArtifact(exe_tests);
run_exe_tests.skip_foreign_checks = true;
// Universal lambda can end up as an exe or a lib. When it is a library,
// we end up changing the root source file away from downstream so we can
// control exports and such. This is just flexilib for now, but we could
// end up in a situation where we need to create an array of libraries
// with various roots that all meet the rest of the build DAG at test_step
// in the future. Scaleway, for instance, is another system that works
// via shared library
const lib_tests = b.addTest(.{
.root_source_file = .{ .path = "src/flexilib.zig" },
.target = target,
.optimize = optimize,
});
_ = try universal_lambda.addModules(b, lib_tests);
var run_lib_tests = b.addRunArtifact(lib_tests);
run_lib_tests.skip_foreign_checks = true;
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build test`
// This will evaluate the `test` step rather than the default, which is "install".
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&run_exe_tests.step);
test_step.dependOn(&run_lib_tests.step);
for (test_targets) |t| {
// Creates steps for unit testing. This only builds the test executable
// but does not run it.
const exe_tests = b.addTest(.{
.root_source_file = .{ .path = "src/test.zig" },
.target = t,
.optimize = optimize,
});
_ = try universal_lambda.addModules(b, exe_tests);
var run_exe_tests = b.addRunArtifact(exe_tests);
run_exe_tests.skip_foreign_checks = true;
test_step.dependOn(&run_exe_tests.step);
// Universal lambda can end up as an exe or a lib. When it is a library,
// we end up changing the root source file away from downstream so we can
// control exports and such. This is just flexilib for now, but we could
// end up in a situation where we need to create an array of libraries
// with various roots that all meet the rest of the build DAG at test_step
// in the future. Scaleway, for instance, is another system that works
// via shared library
// const lib_tests = b.addTest(.{
// .root_source_file = .{ .path = "src/flexilib.zig" },
// .target = t,
// .optimize = optimize,
// });
// _ = try universal_lambda.addModules(b, lib_tests);
//
// var run_lib_tests = b.addRunArtifact(lib_tests);
// run_lib_tests.skip_foreign_checks = true;
// // This creates a build step. It will be visible in the `zig build --help` menu,
// // and can be selected like this: `zig build test`
// // This will evaluate the `test` step rather than the default, which is "install".
// test_step.dependOn(&run_lib_tests.step);
}
}
pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile) !void {