Skip to content

Commit

Permalink
chore: zig 0.13.0-dev.211+6a65561e3
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed May 16, 2024
1 parent 2c401b4 commit a733e96
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 121 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ jobs:
run: zig build-lib -dynamic tests/utils/foreign.zig && mv libforeign.* tests/utils/

- name: Run tests Debug
run: zig build test
run: zig build -Dci test
- name: Cleanup
run: rm -rf zig-out zig-cache
- name: Run tests Debug with JIT always on
run: zig build -Djit_always_on test
run: zig build -Dci -Djit_always_on test
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run tests ReleaseSafe
run: zig build -Doptimize=ReleaseSafe test
run: zig build -Dci -Doptimize=ReleaseSafe test
- name: Cleanup
run: rm -rf zig-out zig-cache
- name: Run tests ReleaseSafe with JIT always on
run: zig build -Doptimize=ReleaseSafe -Djit_always_on test
run: zig build -Dci -Doptimize=ReleaseSafe -Djit_always_on test
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run tests ReleaseFast
run: zig build -Doptimize=ReleaseFast test
run: zig build -Dci -Doptimize=ReleaseFast test
- name: Cleanup
run: rm -rf zig-out zig-cache
- name: Run tests ReleaseFast with JIT always on
run: zig build -Doptimize=ReleaseFast -Djit_always_on test
run: zig build -Dci -Doptimize=ReleaseFast -Djit_always_on test
- name: Cleanup
run: rm -rf zig-out zig-cache
test-linux:
Expand All @@ -68,29 +68,29 @@ jobs:
run: zig build-lib -dynamic tests/utils/foreign.zig && mv libforeign.* tests/utils/

- name: Run tests Debug
run: zig build test
run: zig build -Dci test
- name: Cleanup
run: rm -rf zig-out zig-cache
- name: Run tests Debug with JIT always on
run: zig build -Djit_always_on test
run: zig build -Dci -Djit_always_on test
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run tests ReleaseSafe
run: zig build -Doptimize=ReleaseSafe test
run: zig build -Dci -Doptimize=ReleaseSafe test
- name: Cleanup
run: rm -rf zig-out zig-cache
- name: Run tests ReleaseSafe with JIT always on
run: zig build -Doptimize=ReleaseSafe -Djit_always_on test
run: zig build -Dci -Doptimize=ReleaseSafe -Djit_always_on test
- name: Cleanup
run: rm -rf zig-out zig-cache

- name: Run tests ReleaseFast
run: zig build -Doptimize=ReleaseFast test
run: zig build -Dci -Doptimize=ReleaseFast test
- name: Cleanup
run: rm -rf zig-out zig-cache
- name: Run tests ReleaseFast with JIT always on
run: zig build -Doptimize=ReleaseFast -Djit_always_on test
run: zig build -Dci -Doptimize=ReleaseFast -Djit_always_on test
- name: Cleanup
run: rm -rf zig-out zig-cache
lint:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A small/lightweight statically typed scripting language written in Zig

## How to build and install

_Latest zig version supported: 0.13.0-dev.73+db890dbae_
_Latest zig version supported: 0.13.0-dev.211+6a65561e3_

### Requirements
- Since this is built with Zig, you should be able to build buzz on a wide variety of architectures even though this has only been tested on x86/M1.
Expand Down
133 changes: 42 additions & 91 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const BuzzBuildOptions = struct {
cycle_limit: ?u128,
recursive_call_limit: ?u32,
stack_size: usize = 100_000,
ci: bool,

pub fn step(self: @This(), b: *Build) *Build.Module {
var options = b.addOptions();
Expand All @@ -78,6 +79,7 @@ const BuzzBuildOptions = struct {
options.addOption(@TypeOf(self.cycle_limit), "cycle_limit", self.cycle_limit);
options.addOption(@TypeOf(self.recursive_call_limit), "recursive_call_limit", self.recursive_call_limit);
options.addOption(@TypeOf(self.stack_size), "stack_size", self.stack_size);
options.addOption(@TypeOf(self.ci), "ci", self.ci);

self.debug.step(options);
self.gc.step(options);
Expand All @@ -98,7 +100,7 @@ fn getBuzzPrefix(b: *Build) ![]const u8 {
pub fn build(b: *Build) !void {
// Check minimum zig version
const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse("0.13.0-dev.73+db890dbae") catch return;
const min_zig = std.SemanticVersion.parse("0.13.0-dev.211+6a65561e3") catch return;
if (current_zig.order(min_zig).compare(.lt)) {
@panic(b.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{ current_zig, min_zig }));
}
Expand Down Expand Up @@ -147,6 +149,11 @@ pub fn build(b: *Build) !void {
"stack_size",
"Stack maximum size",
) orelse 100_000,
.ci = b.option(
bool,
"ci",
"Build for CI (will add specific include paths)",
) orelse false,
.mimalloc = !is_wasm and b.option(
bool,
"mimalloc",
Expand Down Expand Up @@ -273,15 +280,15 @@ pub fn build(b: *Build) !void {
}

includes.appendSlice(&[_][]const u8{
"/usr/local/include",
"/usr/include",
// "/usr/local/include",
// "/usr/include",
"./vendors/mir",
"./vendors/mimalloc/include",
}) catch unreachable;

llibs.appendSlice(&[_][]const u8{
"/usr/local/lib",
"/usr/lib",
// "/usr/local/lib",
// "/usr/lib",
"./vendors/mir",
}) catch unreachable;

Expand All @@ -298,33 +305,9 @@ pub fn build(b: *Build) !void {
else
null;

// If macOS, add homebrew paths
if (builtin.os.tag == .macos) {
const result = std.ChildProcess.run(
.{
.allocator = b.allocator,
.argv = &[_][]const u8{ "brew", "--prefix" },
},
) catch null;

const prefix = if (result) |r|
std.mem.trim(u8, r.stdout, "\n")
else
std.posix.getenv("HOMEBREW_PREFIX") orelse "/opt/homebrew";

var include = std.ArrayList(u8).init(b.allocator);
include.writer().print("{s}{s}include", .{ prefix, std.fs.path.sep_str }) catch unreachable;

var lib = std.ArrayList(u8).init(b.allocator);
lib.writer().print("{s}{s}lib", .{ prefix, std.fs.path.sep_str }) catch unreachable;

includes.append(include.items) catch unreachable;
llibs.append(lib.items) catch unreachable;
}

var exe = b.addExecutable(.{
.name = "buzz",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = build_mode,
});
Expand All @@ -349,10 +332,10 @@ pub fn build(b: *Build) !void {
b.step("run", "run buzz").dependOn(&run_exe.step);

for (includes.items) |include| {
exe.addIncludePath(.{ .path = include });
exe.addIncludePath(b.path(include));
}
for (llibs.items) |lib| {
exe.addLibraryPath(.{ .path = lib });
exe.addLibraryPath(b.path(lib));
}
for (sys_libs.items) |slib| {
// FIXME: if mir is linked as static library (libmir.a), here also need to link libc
Expand All @@ -369,18 +352,18 @@ pub fn build(b: *Build) !void {
// Building buzz api library
var lib = b.addSharedLibrary(.{
.name = "buzz",
.root_source_file = .{ .path = "src/buzz_api.zig" },
.root_source_file = b.path("src/buzz_api.zig"),
.target = target,
.optimize = build_mode,
});

b.installArtifact(lib);

for (includes.items) |include| {
lib.addIncludePath(.{ .path = include });
lib.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
lib.addLibraryPath(.{ .path = llib });
lib.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
lib.linkSystemLibrary(slib);
Expand Down Expand Up @@ -440,8 +423,16 @@ pub fn build(b: *Build) !void {
for (libraries) |library| {
// Copy buzz definitions
const step = b.addInstallLibFile(
.{ .path = b.fmt("src/lib/{s}.buzz", .{library.name}) },
b.fmt("buzz/{s}.buzz", .{library.name}),
b.path(
b.fmt(
"src/lib/{s}.buzz",
.{library.name},
),
),
b.fmt(
"buzz/{s}.buzz",
.{library.name},
),
);
install_step.dependOn(&step.step);

Expand All @@ -451,7 +442,7 @@ pub fn build(b: *Build) !void {

var std_lib = b.addSharedLibrary(.{
.name = library.name,
.root_source_file = .{ .path = library.path.? },
.root_source_file = b.path(library.path.?),
.target = target,
.optimize = build_mode,
});
Expand All @@ -462,10 +453,10 @@ pub fn build(b: *Build) !void {

// No need to link anything when building for wasm since everything is static
for (includes.items) |include| {
std_lib.addIncludePath(.{ .path = include });
std_lib.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
std_lib.addLibraryPath(.{ .path = llib });
std_lib.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
std_lib.linkSystemLibrary(slib);
Expand All @@ -487,33 +478,22 @@ pub fn build(b: *Build) !void {
std_lib.linkLibrary(lib);
std_lib.root_module.addImport("build_options", build_option_module);

// Adds `$BUZZ_PATH/lib` and `/usr/local/lib/buzz` as search path for other shared lib referenced by this one (libbuzz.dylib most of the time)
std_lib.addRPath(
.{
.path = b.fmt(
"{s}" ++ std.fs.path.sep_str ++ "lib/buzz",
.{try getBuzzPrefix(b)},
),
},
);
std_lib.addRPath(.{ .path = "/usr/local/lib/buzz" });

b.default_step.dependOn(&std_lib.step);

library_steps.append(std_lib) catch unreachable;
}
}

const tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = build_mode,
});
for (includes.items) |include| {
tests.addIncludePath(.{ .path = include });
tests.addIncludePath(b.path(include));
}
for (llibs.items) |llib| {
tests.addLibraryPath(.{ .path = llib });
tests.addLibraryPath(b.path(llib));
}
for (sys_libs.items) |slib| {
tests.linkSystemLibrary(slib);
Expand All @@ -534,7 +514,7 @@ pub fn build(b: *Build) !void {

const test_step = b.step("test", "Run all the tests");
const run_tests = b.addRunArtifact(tests);
run_tests.cwd = Build.LazyPath{ .path = "." };
run_tests.cwd = b.path(".");
run_tests.setEnvironmentVariable("BUZZ_PATH", try getBuzzPrefix(b));
run_tests.step.dependOn(install_step); // wait for libraries to be installed
test_step.dependOn(&run_tests.step);
Expand All @@ -547,15 +527,15 @@ pub fn build(b: *Build) !void {
pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) !*Build.Step.Compile {
const copyFiles = b.addWriteFiles();
copyFiles.addCopyFileToSource(
.{ .path = "vendors/pcre2/src/config.h.generic" },
b.path("vendors/pcre2/src/config.h.generic"),
"vendors/pcre2/src/config.h",
);
copyFiles.addCopyFileToSource(
.{ .path = "vendors/pcre2/src/pcre2.h.generic" },
b.path("vendors/pcre2/src/pcre2.h.generic"),
"vendors/pcre2/src/pcre2.h",
);
copyFiles.addCopyFileToSource(
.{ .path = "vendors/pcre2/src/pcre2_chartables.c.dist" },
b.path("vendors/pcre2/src/pcre2_chartables.c.dist"),
"vendors/pcre2/src/pcre2_chartables.c",
);

Expand All @@ -564,7 +544,7 @@ pub fn buildPcre2(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin
.target = target,
.optimize = optimize,
});
lib.addIncludePath(.{ .path = "src" });
lib.addIncludePath(b.path("src"));
lib.addCSourceFiles(
.{
.files = &.{
Expand Down Expand Up @@ -619,38 +599,9 @@ pub fn buildMimalloc(b: *Build, target: Build.ResolvedTarget, optimize: std.buil
},
);

lib.addIncludePath(.{ .path = "./vendors/mimalloc/include" });
lib.addIncludePath(b.path("./vendors/mimalloc/include"));
lib.linkLibC();

if (lib.root_module.resolved_target.?.result.os.tag == .macos) {
var macOS_sdk_path = std.ArrayList(u8).init(b.allocator);
try macOS_sdk_path.writer().print(
"{s}/usr/include",
.{
(std.ChildProcess.run(.{
.allocator = b.allocator,
.argv = &.{
"xcrun",
"--show-sdk-path",
},
.cwd = b.pathFromRoot("."),
.expand_arg0 = .expand,
}) catch {
std.debug.print("Warning: failed to get MacOSX sdk path", .{});
unreachable;
}).stdout,
},
);

lib.addSystemIncludePath(.{ .path = macOS_sdk_path.items });
// Github macos-12 runner (https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md).
lib.addSystemIncludePath(.{ .path = "/Applications/Xcode_14.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX14.0.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include" });
lib.addSystemIncludePath(.{ .path = "/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include" });
}

lib.addCSourceFiles(
.{
.files = &.{
Expand Down Expand Up @@ -690,7 +641,7 @@ pub fn buildLinenoise(b: *Build, target: Build.ResolvedTarget, optimize: std.bui
.optimize = optimize,
});

lib.addIncludePath(.{ .path = "vendors/linenoise" });
lib.addIncludePath(b.path("vendors/linenoise"));
lib.addCSourceFiles(
.{
.files = &.{
Expand Down Expand Up @@ -738,7 +689,7 @@ pub fn buildWasmReplDemo(b: *Build, exe: *Build.Step.Compile) void {
b.getInstallStep().dependOn(&esbuild.step);

const copyRepl = b.addInstallBinFile(
.{ .path = "src/repl.html" },
b.path("src/repl.html"),
"repl.html",
);
b.getInstallStep().dependOn(&copyRepl.step);
Expand Down
Loading

0 comments on commit a733e96

Please sign in to comment.