wip trying to get orca wasm binary to build
This commit is contained in:
parent
0fd255682d
commit
02c1938a43
|
@ -0,0 +1,19 @@
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
:: compile wasm module
|
||||||
|
set wasmFlags=--target=wasm32^
|
||||||
|
--no-standard-libraries ^
|
||||||
|
-fno-builtin ^
|
||||||
|
-Wl,--no-entry ^
|
||||||
|
-Wl,--export-dynamic ^
|
||||||
|
-g ^
|
||||||
|
-O2 ^
|
||||||
|
-mbulk-memory ^
|
||||||
|
-D__ORCA__ ^
|
||||||
|
-isystem ..\..\src\libc-shim\include ^
|
||||||
|
-I..\..\ext -I ..\..\src
|
||||||
|
|
||||||
|
clang %wasmFlags% -o .\liborca.a ..\..\src\orca.c ..\..\src\libc-shim\src\*.c
|
||||||
|
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
|
||||||
|
|
||||||
|
zig build bundle
|
|
@ -1,48 +1,96 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) void {
|
fn addSourceString(str: []const u8, strings: *std.ArrayList(u8), sources: *std.ArrayList([]const u8)) !void {
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
var begin = strings.items.len;
|
||||||
|
try strings.appendSlice(str);
|
||||||
|
var realstring = strings.items[begin..];
|
||||||
|
try sources.append(realstring);
|
||||||
|
}
|
||||||
|
|
||||||
// builds the wasm module out of the orca C sources and main.zig
|
pub fn build(b: *std.Build) !void {
|
||||||
const lib = b.addSharedLibrary(.{
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
.name = "module",
|
const wasm_target = std.zig.CrossTarget{
|
||||||
.root_source_file = .{ .path = "src/main.zig" },
|
|
||||||
.target = std.zig.CrossTarget{
|
|
||||||
.cpu_arch = .wasm32,
|
.cpu_arch = .wasm32,
|
||||||
.os_tag = .freestanding,
|
.os_tag = .freestanding,
|
||||||
},
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
|
||||||
lib.rdynamic = true;
|
|
||||||
|
|
||||||
// const orca_sources = [_][]const u8{"../../src/orca.c"}; //, "../../src/libc-shim/src/*.c"
|
|
||||||
const orca_sources = [_][]const u8{ "../../src/orca.c", "../../src/libc-shim/src/string.c" };
|
|
||||||
const orca_compile_opts = [_][]const u8{
|
|
||||||
"-D__ORCA__",
|
|
||||||
"--no-standard-libraries",
|
|
||||||
"-fno-builtin",
|
|
||||||
"-I../../src",
|
|
||||||
"-I../../src/libc-shim/include",
|
|
||||||
"-I../../ext",
|
|
||||||
"-Wl,--export-all",
|
|
||||||
"-g",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -isystem ..\..\src\libc-shim\include ^
|
//NOTE(reuben) - Ideally we would build the orca wasm lib and link it all within build.zig, but there
|
||||||
// -I..\..\ext -I ..\..\src
|
// seems to be a bug where the -mbulk-memory flag is ignored and memory.copy and
|
||||||
|
// memory.fill instructions aren't generated, leading the memcpy and memset instructions
|
||||||
|
// to become infinitely recursive, crashing the program. So for now we build the orca
|
||||||
|
// wasm lib with clang and link it in here.
|
||||||
|
|
||||||
lib.addIncludePath(.{ .path = "../../src" });
|
// var orca_source_strings = try std.ArrayList(u8).initCapacity(b.allocator, 1024 * 4);
|
||||||
lib.addIncludePath(.{ .path = "../../src/libc-shim/include" });
|
// var orca_sources = try std.ArrayList([]const u8).initCapacity(b.allocator, 128);
|
||||||
lib.addIncludePath(.{ .path = "../../ext" });
|
// defer orca_source_strings.deinit();
|
||||||
lib.addCSourceFiles(&orca_sources, &orca_compile_opts);
|
// defer orca_sources.deinit();
|
||||||
|
|
||||||
|
// {
|
||||||
|
// try addSourceString("../../src/orca.c", &orca_source_strings, &orca_sources);
|
||||||
|
|
||||||
|
// var libc_shim_dir = try std.fs.cwd().openIterableDir("../../src/libc-shim/src", .{});
|
||||||
|
// var walker = try libc_shim_dir.walk(b.allocator);
|
||||||
|
// defer walker.deinit();
|
||||||
|
|
||||||
|
// while (try walker.next()) |entry| {
|
||||||
|
// const extension = std.fs.path.extension(entry.path);
|
||||||
|
// if (std.mem.eql(u8, extension, ".c")) {
|
||||||
|
// var path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
|
||||||
|
// var abs_path = try libc_shim_dir.dir.realpath(entry.path, &path_buffer);
|
||||||
|
// try addSourceString(abs_path, &orca_source_strings, &orca_sources);
|
||||||
|
// // std.debug.print("adding libc shim source: {s}\n", .{abs_path});
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const orca_compile_opts = [_][]const u8{
|
||||||
|
// "-D__ORCA__",
|
||||||
|
// "--no-standard-libraries",
|
||||||
|
// "-fno-builtin",
|
||||||
|
// "-isystem ../../src/libc-shim/include",
|
||||||
|
// "-I../../src",
|
||||||
|
// "-I../../ext",
|
||||||
|
// "-O2",
|
||||||
|
// "-mbulk-memory",
|
||||||
|
// "-Wl,--no-entry",
|
||||||
|
// "-Wl,--export-all",
|
||||||
|
// "-g",
|
||||||
|
// };
|
||||||
|
|
||||||
|
// var orca_lib = b.addStaticLibrary(.{
|
||||||
|
// .name = "orca",
|
||||||
|
// .target = wasm_target,
|
||||||
|
// .optimize = optimize,
|
||||||
|
// });
|
||||||
|
// orca_lib.rdynamic = true;
|
||||||
|
// orca_lib.addIncludePath(.{ .path = "../../src" });
|
||||||
|
// orca_lib.addIncludePath(.{ .path = "../../src/libc-shim/include" });
|
||||||
|
// orca_lib.addIncludePath(.{ .path = "../../ext" });
|
||||||
|
// orca_lib.addCSourceFiles(orca_sources.items, &orca_compile_opts);
|
||||||
|
// b.installArtifact(orca_lib);
|
||||||
|
|
||||||
|
// builds the wasm module out of the orca C sources and main.zig
|
||||||
|
const wasm_lib = b.addSharedLibrary(.{
|
||||||
|
.name = "module",
|
||||||
|
.root_source_file = .{ .path = "src/main.zig" },
|
||||||
|
.target = wasm_target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
wasm_lib.rdynamic = true;
|
||||||
|
|
||||||
const orca_module: *std.Build.Module = b.createModule(.{
|
const orca_module: *std.Build.Module = b.createModule(.{
|
||||||
.source_file = .{ .path = "../../src/orca.zig" },
|
.source_file = .{ .path = "../../src/orca.zig" },
|
||||||
});
|
});
|
||||||
lib.addModule("orca", orca_module);
|
wasm_lib.addIncludePath(.{ .path = "../../src" });
|
||||||
|
wasm_lib.addIncludePath(.{ .path = "../../src/libc-shim/include" });
|
||||||
|
wasm_lib.addIncludePath(.{ .path = "../../ext" });
|
||||||
|
wasm_lib.addModule("orca", orca_module);
|
||||||
|
// wasm_lib.linkLibrary(orca_lib);
|
||||||
|
wasm_lib.addLibraryPath(.{ .path = "." });
|
||||||
|
wasm_lib.linkSystemLibrary("orca");
|
||||||
|
|
||||||
// copies the wasm module into zig-out/lib
|
// copies the wasm module into zig-out/wasm_lib
|
||||||
b.installArtifact(lib);
|
b.installArtifact(wasm_lib);
|
||||||
|
|
||||||
// Runs the orca build command
|
// Runs the orca build command
|
||||||
const bundle_cmd_str = [_][]const u8{ "orca", "bundle", "--orca-dir", "../..", "--name", "Calc", "--icon", "icon.png", "--resource-dir", "data", "zig-out/lib/module.wasm" };
|
const bundle_cmd_str = [_][]const u8{ "orca", "bundle", "--orca-dir", "../..", "--name", "Calc", "--icon", "icon.png", "--resource-dir", "data", "zig-out/lib/module.wasm" };
|
||||||
|
|
Loading…
Reference in New Issue