Skip to content

Commit

Permalink
use zig package manager for zig-stable-array
Browse files Browse the repository at this point in the history
  • Loading branch information
rdunnington committed May 25, 2024
1 parent a3e9dba commit 4355788
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 559 deletions.
36 changes: 28 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const std = @import("std");

const Build = std.Build;
const Module = Build.Module;
const ModuleImport = Module.Import;
const CrossTarget = std.zig.CrossTarget;
const CompileStep = std.Build.Step.Compile;

Expand All @@ -20,15 +22,30 @@ pub fn build(b: *Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const stable_array = b.dependency("zig-stable-array", .{
.target = target,
.optimize = optimize,
});

var bench_add_one_step: *CompileStep = buildWasmExe(b, "bench/samples/add-one.zig");
var bench_fibonacci_step: *CompileStep = buildWasmExe(b, "bench/samples/fibonacci.zig");
var bench_mandelbrot_step: *CompileStep = buildWasmExe(b, "bench/samples/mandelbrot.zig");

const stable_array_import = ModuleImport{ .name = "stable-array", .module = stable_array.module("zig-stable-array") };

const bytebox_module: *Build.Module = b.addModule("bytebox", .{
.root_source_file = b.path("src/core.zig"),
.imports = &[_]ModuleImport{stable_array_import},
});

_ = buildExeWithRunStep(b, target, optimize, bytebox_module, .{
// exe.root_module.addImport(import.name, import.module);

const imports = [_]ModuleImport{
.{ .name = "bytebox", .module = bytebox_module },
.{ .name = "stable-array", .module = stable_array.module("zig-stable-array") },
};

_ = buildExeWithRunStep(b, target, optimize, &imports, .{
.exe_name = "bytebox",
.root_src = "run/main.zig",
.step_name = "run",
Expand All @@ -41,20 +58,21 @@ pub fn build(b: *Build) void {
&bench_fibonacci_step.step,
&bench_mandelbrot_step.step,
};
_ = buildExeWithRunStep(b, target, optimize, bytebox_module, .{
_ = buildExeWithRunStep(b, target, optimize, &imports, .{
.exe_name = "bench",
.root_src = "bench/main.zig",
.step_name = "bench",
.description = "Run the benchmark suite",
.step_dependencies = &bench_steps,
});

const lib_bytebox = b.addStaticLibrary(.{
const lib_bytebox: *Build.Step.Compile = b.addStaticLibrary(.{
.name = "bytebox",
.root_source_file = b.path("src/cffi.zig"),
.target = target,
.optimize = optimize,
});
lib_bytebox.root_module.addImport(stable_array_import.name, stable_array_import.module);
lib_bytebox.installHeader(b.path("src/bytebox.h"), "bytebox.h");
b.installArtifact(lib_bytebox);

Expand All @@ -69,7 +87,7 @@ pub fn build(b: *Build) void {
unit_test_step.dependOn(&run_unit_tests.step);

// wasm tests
const wasm_testsuite_step = buildExeWithRunStep(b, target, optimize, bytebox_module, .{
const wasm_testsuite_step = buildExeWithRunStep(b, target, optimize, &imports, .{
.exe_name = "test-wasm",
.root_src = "test/wasm/main.zig",
.step_name = "test-wasm",
Expand Down Expand Up @@ -103,7 +121,7 @@ pub fn build(b: *Build) void {

b.getInstallStep().dependOn(&compile_memtest.step);

mem64_test_step = buildExeWithRunStep(b, target, optimize, bytebox_module, .{
mem64_test_step = buildExeWithRunStep(b, target, optimize, &imports, .{
.exe_name = "test-mem64",
.root_src = "test/mem64/main.zig",
.step_name = "test-mem64",
Expand All @@ -121,15 +139,17 @@ pub fn build(b: *Build) void {
}
}

fn buildExeWithRunStep(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.Mode, bytebox_module: *Build.Module, opts: ExeOpts) *Build.Step {
const exe = b.addExecutable(.{
fn buildExeWithRunStep(b: *Build, target: Build.ResolvedTarget, optimize: std.builtin.Mode, imports: []const ModuleImport, opts: ExeOpts) *Build.Step {
const exe: *Build.Step.Compile = b.addExecutable(.{
.name = opts.exe_name,
.root_source_file = b.path(opts.root_src),
.target = target,
.optimize = optimize,
});

exe.root_module.addImport("bytebox", bytebox_module);
for (imports) |import| {
exe.root_module.addImport(import.name, import.module);
}

// exe.emit_asm = if (opts.should_emit_asm) .emit else .default;
b.installArtifact(exe);
Expand Down
7 changes: 6 additions & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@
"LICENSE",
"README.md",
},
.dependencies = .{},
.dependencies = .{
.@"zig-stable-array" = .{
.url = "https://github.com/rdunnington/zig-stable-array/archive/bbb120cd0e4a8a83a21217e67ab6d7697a809756.tar.gz",
.hash = "12202fe89e68d38484a313816e571eca786b36775e3aa2831def7b20815fa81831f1",
},
},
}
2 changes: 1 addition & 1 deletion src/cffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ModuleDefinition = core.ModuleDefinition;
const ModuleInstance = core.ModuleInstance;
const ModuleImportPackage = core.ModuleImportPackage;

const StableArray = @import("zig-stable-array/stable_array.zig").StableArray;
const StableArray = @import("stable-array").StableArray;

// C interface
const CSlice = extern struct {
Expand Down
2 changes: 1 addition & 1 deletion src/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const std = @import("std");

pub const StableArray = @import("zig-stable-array/stable_array.zig").StableArray;
pub const StableArray = @import("stable-array").StableArray;

pub fn decodeLEB128(comptime T: type, reader: anytype) !T {
if (@typeInfo(T).Int.signedness == .signed) {
Expand Down
2 changes: 1 addition & 1 deletion src/stringpool.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const StableArray = @import("zig-stable-array/stable_array.zig").StableArray;
const StableArray = @import("stable-array").StableArray;

const hashString = std.hash_map.hashString;
const StringHashLookupTable = std.hash_map.AutoHashMap(u64, usize);
Expand Down
54 changes: 0 additions & 54 deletions src/zig-stable-array/LICENSE

This file was deleted.

19 changes: 0 additions & 19 deletions src/zig-stable-array/README.md

This file was deleted.

Loading

0 comments on commit 4355788

Please sign in to comment.