Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use zig package manager for zig-stable-array #46

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 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,35 +58,37 @@ 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);

// Unit tests
const unit_tests = b.addTest(.{
const unit_tests: *Build.Step.Compile = b.addTest(.{
.root_source_file = b.path("src/tests.zig"),
.target = target,
.optimize = optimize,
});
unit_tests.root_module.addImport(stable_array_import.name, stable_array_import.module);
const run_unit_tests = b.addRunArtifact(unit_tests);
const unit_test_step = b.step("test-unit", "Run unit tests");
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 +122,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 +140,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
Loading