Skip to content

Commit

Permalink
Update to Zig 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zackradisic committed Oct 27, 2024
1 parent 52e378b commit fddcbac
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
zig-out/
zig-cache/
.zig-cache/
node_modules/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ vm-wasm: zig-out/bin/tyvm.wasm site/public/tyvm.wasm

.PHONY: clean
clean:
rm -rf target zig-out zig-cache
rm -rf target zig-out .zig-cache

run-wasm: vm-wasm
wasmtime ./zig-out/bin/tyvm.wasm --dir=.
Expand Down
25 changes: 12 additions & 13 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});

const is_wasm = target.cpu_arch != null and target.cpu_arch.?.isWasm();
const is_wasm = target.query.cpu_arch != null and target.query.cpu_arch.?.isWasm();

const out = exe: {
if (is_wasm) {
var lib = b.addExecutable(.{
.name = "tyvm",
.root_source_file = .{ .path = "vm/main_wasm.zig" },
.root_source_file = .{ .cwd_relative = "vm/main_wasm.zig" },
.target = target,
.optimize = optimize,
.link_libc = true,
Expand All @@ -30,15 +30,15 @@ pub fn build(b: *std.Build) void {
// .cpu_arch = .wasm64,
// .os_tag = .emscripten,
// };
lib.export_symbol_names = &.{ "init", "get_function", "get_global_function", "run", "alloc", "dealloc", "is_game", "jump", "reset" };
lib.root_module.export_symbol_names = &.{ "init", "get_function", "get_global_function", "run", "alloc", "dealloc", "is_game", "jump", "reset" };
lib.initial_memory = 65536 * 65536;
lib.max_memory = 65536 * 65536;
lib.dwarf_format = .@"32";
lib.root_module.dwarf_format = .@"32";
break :exe lib;
}
const exe = b.addExecutable(.{
.name = "tyvm",
.root_source_file = .{ .path = "vm/main.zig" },
.root_source_file = .{ .cwd_relative = "vm/main.zig" },
.target = target,
.optimize = optimize,
.link_libc = true,
Expand All @@ -47,25 +47,24 @@ pub fn build(b: *std.Build) void {
};

out.linkSystemLibrary("tyvm_compiler");
out.addIncludePath(.{ .path = "./include" });
out.addIncludePath(.{ .cwd_relative = "./include" });
if (is_wasm) {
if (optimize == .Debug) {
out.addLibraryPath(.{ .path = "./target/wasm32-wasi/debug" });
out.addLibraryPath(.{ .cwd_relative = "./target/wasm32-wasi/debug" });
} else {
out.addLibraryPath(.{ .path = "./target/wasm32-wasi/release" });
out.addLibraryPath(.{ .cwd_relative = "./target/wasm32-wasi/release" });
}
} else {
if (optimize == .Debug) {
out.addLibraryPath(.{ .path = "./target/debug" });
out.addLibraryPath(.{ .cwd_relative = "./target/debug" });
} else {
out.addLibraryPath(.{ .path = "./target/release" });
out.addLibraryPath(.{ .cwd_relative = "./target/release" });
}
}

const ENABLE_DEBUG_SYMBOLS = true;
if (comptime ENABLE_DEBUG_SYMBOLS) {
out.dll_export_fns = true;
out.strip = false;
out.root_module.strip = false;
out.export_table = true;
// out.symb
out.linkLibC();
Expand Down Expand Up @@ -104,7 +103,7 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "vm/vm.zig" },
.root_source_file = .{ .cwd_relative = "vm/vm.zig" },
.target = target,
.optimize = optimize,
});
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
in rec {
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
zigpkgs.master-2023-12-13 # the same version used in Bun
zigpkgs."0.13.0" # the same version used in Bun
# zls version used is master
# zls.zls
];
Expand Down
2 changes: 1 addition & 1 deletion test/fib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type FibIter<
N extends number,
I extends number,
NminusOne extends number,
NminusTwo extends number,
NminusTwo extends number
> = N extends I
? Add<NminusOne, NminusTwo>
: FibIter<N, Add<I, 1>, Add<NminusOne, NminusTwo>, NminusOne>;
Expand Down
4 changes: 2 additions & 2 deletions vm/tyvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub fn logger(comptime tag: anytype, comptime disabled: bool) _log_fn {

if (!evaluated_disable) {
evaluated_disable = true;
if (std.os.getenv("TYVM_DEBUG_" ++ tagname)) |val| {
if (std.posix.getenv("TYVM_DEBUG_" ++ tagname)) |val| {
really_disable = std.mem.eql(u8, val, "0");
} else if (std.os.getenv("TYVM_DEBUG_LOGS")) |val| {
} else if (std.posix.getenv("TYVM_DEBUG_LOGS")) |val| {
really_disable = really_disable or std.mem.eql(u8, val, "0");
}
}
Expand Down
2 changes: 1 addition & 1 deletion vm/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,7 @@ pub const GC = struct {

pub fn init(vm: *VM) !GC {
const both: []u8 = brk: {
if (tyvm.isPosix) break :brk try std.os.mmap(null, SPACE_SIZE * 2, std.os.PROT.READ | std.os.PROT.WRITE, std.os.MAP.PRIVATE | std.os.MAP.ANONYMOUS, -1, 0);
if (tyvm.isPosix) break :brk try std.posix.mmap(null, SPACE_SIZE * 2, std.posix.PROT.READ | std.posix.PROT.WRITE, std.posix.MAP{ .TYPE = .PRIVATE, .ANONYMOUS = true }, -1, 0);
break :brk try std.heap.c_allocator.alignedAlloc(u8, 8, SPACE_SIZE * 2);
};
return .{
Expand Down

0 comments on commit fddcbac

Please sign in to comment.