Skip to content

Commit ecb6b0f

Browse files
committed
feat: build, test and release for mulitple architectures
1 parent c2e0af1 commit ecb6b0f

6 files changed

Lines changed: 11510 additions & 5375 deletions

File tree

Justfile

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,13 @@ build:
77
zig build
88

99
release: build
10-
test -f ./zig-out/lib/zig.h || cp "$(zig env | jq -r .lib_dir)/zig.h" ./includes/zig.h
11-
12-
rm -rf dist/
13-
cp -r ./zig-out/lib dist/
14-
echo "size of core.c: $(cat dist/core.c | wc -l)"
15-
16-
# Append valgrind_wrapper.c to core.c
17-
cat src/helpers/valgrind_wrapper.c >> dist/core.c
10+
sh scripts/release.sh
1811

1912
test:
2013
zig build test --summary all
2114

2215
test-valgrind:
23-
rm /tmp/runner*.fifo || true
24-
25-
clang -O3 src/tests/main.c dist/core.c -I includes/ -o clang-main && ./clang-main
26-
valgrind ./clang-main
27-
28-
gcc -O3 src/tests/main.c dist/core.c -I includes/ -o gcc-main && ./gcc-main
29-
valgrind ./gcc-main
30-
31-
rm -rf clang-main gcc-main
16+
sh scripts/test-valgrind.sh
3217

3318
fmt:
3419
zig fmt src

build.zig

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
const std = @import("std");
22

3-
pub fn build(b: *std.Build) void {
4-
const optimize = b.standardOptimizeOption(.{});
5-
const target = b.standardTargetOptions(.{ .default_target = .{ .ofmt = .c } });
6-
7-
// Core Library
8-
//
3+
fn buildForArch(
4+
b: *std.Build,
5+
arch: std.Target.Cpu.Arch,
6+
name: []const u8,
7+
) void {
98
const libcore = b.addStaticLibrary(.{
10-
.name = "core",
9+
.name = name,
1110
.root_source_file = b.path("src/c.zig"),
12-
.target = target,
13-
.optimize = optimize,
11+
.target = b.resolveTargetQuery(.{ .ofmt = .c, .cpu_arch = arch }),
12+
.optimize = .ReleaseSmall,
1413
.link_libc = true,
1514
.strip = true,
15+
.pic = true,
1616
});
1717
libcore.no_builtin = true;
1818
b.installArtifact(libcore);
19+
}
20+
21+
pub fn build(b: *std.Build) void {
22+
buildForArch(b, .aarch64, "core-aarch64");
23+
buildForArch(b, .x86_64, "core-x86_64");
1924

2025
// Tests
2126
//
22-
const test_main = b.addTest(.{ .root_source_file = b.path("src/root.zig"), .optimize = optimize, .link_libc = true, .test_runner = .{ .path = b.path("src/tests/runner.zig"), .mode = .simple } });
27+
const test_main = b.addTest(.{ .root_source_file = b.path("src/root.zig"), .optimize = .ReleaseSafe, .link_libc = true, .test_runner = .{ .path = b.path("src/tests/runner.zig"), .mode = .simple } });
2328
test_main.addCSourceFile(.{ .file = b.path("src/helpers/valgrind_wrapper.c") });
2429
test_main.addIncludePath(b.path("includes"));
2530
test_main.linkLibC();

0 commit comments

Comments
 (0)