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 build.zig instead of build.sh #1

Merged
merged 4 commits into from
Oct 10, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/zig-cache
10 changes: 0 additions & 10 deletions build.sh

This file was deleted.

129 changes: 129 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
const optimize = b.standardOptimizeOption(.{});
const orca_dep = b.dependency("orca", .{});

const app = b.addSharedLibrary(.{
.name = "module",
.target = .{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
.cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}),
},
.optimize = optimize,
.root_source_file = .{ .path = "src/main.zig" },
});
app.rdynamic = true;
app.disable_sanitize_c = true;
app.defineCMacro("__ORCA__", null);
app.addSystemIncludePath(orca_dep.path("src/libc-shim/include"));
app.addIncludePath(orca_dep.path("src"));
app.addIncludePath(orca_dep.path("src/ext"));

const cflags: []const []const u8 = &.{
"-O2", // works around undefined symbol on __fpclassifyl
};
app.addCSourceFile(.{
.file = orca_dep.path("src/orca.c"),
.flags = cflags,
});
for (libc_shim_files) |libc_shim_file| {
app.addCSourceFile(.{
.file = orca_dep.path(libc_shim_file),
.flags = cflags,
});
}

const orca_exe = b.addExecutable(.{
.name = "orca",
.target = .{},
.optimize = .ReleaseFast,
});
// TODO: add the build.zig logic for building the orca tool itself
// if orca upstream used build.zig then we could just grab the exe from there
const run_orca = b.addRunArtifact(orca_exe);
run_orca.addArgs(&.{ "bundle", "--orca-dir" });
run_orca.addFileArg(orca_dep.path("."));
run_orca.addArgs(&.{ "--name", "UI", "--resource-dir", "data" });
run_orca.addFileArg(app.getEmittedBin());

// TODO what is the output of orca command? for now we will just
// run it in the source dir and let it poop something out
b.getInstallStep().dependOn(&run_orca.step);
}

const libc_shim_files: []const []const u8 = &.{
"src/libc-shim/src/__cos.c",
"src/libc-shim/src/__cosdf.c",
"src/libc-shim/src/__errno_location.c",
"src/libc-shim/src/__math_divzero.c",
"src/libc-shim/src/__math_divzerof.c",
"src/libc-shim/src/__math_invalid.c",
"src/libc-shim/src/__math_invalidf.c",
"src/libc-shim/src/__math_oflow.c",
"src/libc-shim/src/__math_oflowf.c",
"src/libc-shim/src/__math_uflow.c",
"src/libc-shim/src/__math_uflowf.c",
"src/libc-shim/src/__math_xflow.c",
"src/libc-shim/src/__math_xflowf.c",
"src/libc-shim/src/__rem_pio2.c",
"src/libc-shim/src/__rem_pio2_large.c",
"src/libc-shim/src/__rem_pio2f.c",
"src/libc-shim/src/__sin.c",
"src/libc-shim/src/__sindf.c",
"src/libc-shim/src/__tan.c",
"src/libc-shim/src/__tandf.c",
"src/libc-shim/src/abs.c",
"src/libc-shim/src/acos.c",
"src/libc-shim/src/acosf.c",
"src/libc-shim/src/asin.c",
"src/libc-shim/src/asinf.c",
"src/libc-shim/src/atan.c",
"src/libc-shim/src/atan2.c",
"src/libc-shim/src/atan2f.c",
"src/libc-shim/src/atanf.c",
"src/libc-shim/src/cbrt.c",
"src/libc-shim/src/cbrtf.c",
"src/libc-shim/src/ceil.c",
"src/libc-shim/src/cos.c",
"src/libc-shim/src/cosf.c",
"src/libc-shim/src/exp.c",
"src/libc-shim/src/exp2f_data.c",
"src/libc-shim/src/exp2f_data.h",
"src/libc-shim/src/exp_data.c",
"src/libc-shim/src/exp_data.h",
"src/libc-shim/src/expf.c",
"src/libc-shim/src/fabs.c",
"src/libc-shim/src/fabsf.c",
"src/libc-shim/src/floor.c",
"src/libc-shim/src/fmod.c",
"src/libc-shim/src/libm.h",
"src/libc-shim/src/log.c",
"src/libc-shim/src/log2.c",
"src/libc-shim/src/log2_data.c",
"src/libc-shim/src/log2_data.h",
"src/libc-shim/src/log2f.c",
"src/libc-shim/src/log2f_data.c",
"src/libc-shim/src/log2f_data.h",
"src/libc-shim/src/log_data.c",
"src/libc-shim/src/log_data.h",
"src/libc-shim/src/logf.c",
"src/libc-shim/src/logf_data.c",
"src/libc-shim/src/logf_data.h",
"src/libc-shim/src/pow.c",
"src/libc-shim/src/pow_data.h",
"src/libc-shim/src/powf.c",
"src/libc-shim/src/powf_data.c",
"src/libc-shim/src/powf_data.h",
"src/libc-shim/src/scalbn.c",
"src/libc-shim/src/sin.c",
"src/libc-shim/src/sinf.c",
"src/libc-shim/src/sqrt.c",
"src/libc-shim/src/sqrt_data.c",
"src/libc-shim/src/sqrt_data.h",
"src/libc-shim/src/sqrtf.c",
"src/libc-shim/src/string.c",
"src/libc-shim/src/tan.c",
"src/libc-shim/src/tanf.c",
};
11 changes: 11 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.{
.name = "orca-ui-hello-zig",
.version = "0.0.0",

.dependencies = .{
.orca = .{
.url = "git+https://git.handmade.network/hmn/orca.git#6e4943c2fa7bebcd6682a7b589d680d08634db77",
.hash = "122055608ef2919e346ca49d43daf962a552ab49ee8a66ab4e07bed6b77946a26600",
},
},
}