From 697bdb9262d205a176a70a2ba7eb9bdff028a4b0 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Sun, 28 Jul 2024 12:07:09 +1000 Subject: [PATCH] WIP add script for zig platforms glue source --- .gitignore | 2 ++ copy-zig-glue-files.sh | 5 +++++ crates/cli/tests/benchmarks/platform/host.zig | 16 ++++++++-------- crates/compiler/build/src/link.rs | 8 -------- 4 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 copy-zig-glue-files.sh diff --git a/.gitignore b/.gitignore index 11551646a4..5938cd938a 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,5 @@ crates/glue/tests/fixtures/*/build.rs crates/glue/tests/fixtures/*/host.c crates/glue/tests/fixtures/*/src/main.rs crates/glue/tests/fixtures/*/test_glue/ + +**/platform/glue diff --git a/copy-zig-glue-files.sh b/copy-zig-glue-files.sh new file mode 100644 index 0000000000..e27cd7308a --- /dev/null +++ b/copy-zig-glue-files.sh @@ -0,0 +1,5 @@ + +BUILTINS_DIR=crates/compiler/builtins/bitcode/src + +mkdir -p crates/cli/tests/benchmarks/platform/glue +cp -r $BUILTINS_DIR crates/cli/tests/benchmarks/platform/glue diff --git a/crates/cli/tests/benchmarks/platform/host.zig b/crates/cli/tests/benchmarks/platform/host.zig index f227605d28..e7d85814e3 100644 --- a/crates/cli/tests/benchmarks/platform/host.zig +++ b/crates/cli/tests/benchmarks/platform/host.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const str = @import("glue").str; +const str = @import("./glue/src/str.zig"); const RocStr = str.RocStr; const testing = std.testing; const expectEqual = testing.expectEqual; @@ -27,7 +27,7 @@ const DEBUG: bool = false; export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque { if (DEBUG) { - var ptr = malloc(size); + const ptr = malloc(size); const stdout = std.io.getStdOut().writer(); stdout.print("alloc: {d} (alignment {d}, size {d})\n", .{ ptr, alignment, size }) catch unreachable; return ptr; @@ -99,13 +99,13 @@ fn roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_ comptime { if (builtin.os.tag == .macos or builtin.os.tag == .linux) { - @export(roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong }); - @export(roc_mmap, .{ .name = "roc_mmap", .linkage = .Strong }); - @export(roc_shm_open, .{ .name = "roc_shm_open", .linkage = .Strong }); + @export(roc_getppid, .{ .name = "roc_getppid", .linkage = .strong }); + @export(roc_mmap, .{ .name = "roc_mmap", .linkage = .strong }); + @export(roc_shm_open, .{ .name = "roc_shm_open", .linkage = .strong }); } if (builtin.os.tag == .windows) { - @export(roc_getppid_windows_stub, .{ .name = "roc_getppid", .linkage = .Strong }); + @export(roc_getppid_windows_stub, .{ .name = "roc_getppid", .linkage = .strong }); } } @@ -117,7 +117,7 @@ pub fn main() !u8 { // The size might be zero; if so, make it at least 8 so that we don't have a nullptr const size = @max(@as(usize, @intCast(roc__mainForHost_1_exposed_size())), 8); const raw_output = roc_alloc(@as(usize, @intCast(size)), @alignOf(u64)).?; - var output = @as([*]u8, @ptrCast(raw_output)); + const output = @as([*]u8, @ptrCast(raw_output)); defer { roc_dealloc(raw_output, @alignOf(u64)); @@ -149,7 +149,7 @@ fn call_the_closure(closure_data_pointer: [*]u8) void { // The size might be zero; if so, make it at least 8 so that we don't have a nullptr const size = @max(roc__mainForHost_0_result_size(), 8); const raw_output = allocator.alignedAlloc(u8, @alignOf(u64), @as(usize, @intCast(size))) catch unreachable; - var output = @as([*]u8, @ptrCast(raw_output)); + const output = @as([*]u8, @ptrCast(raw_output)); defer { allocator.free(raw_output); diff --git a/crates/compiler/build/src/link.rs b/crates/compiler/build/src/link.rs index 5195d4cd64..ed62ad771c 100644 --- a/crates/compiler/build/src/link.rs +++ b/crates/compiler/build/src/link.rs @@ -171,10 +171,6 @@ pub fn build_zig_host_native( zig_cmd.args([ zig_host_src, &format!("-femit-bin={emit_bin}"), - "--mod", - &format!("glue::{}", find_zig_glue_path().to_str().unwrap()), - "--deps", - "glue", // include libc "-lc", // cross-compile? @@ -243,10 +239,6 @@ pub fn build_zig_host_native( zig_cmd.args(&[ zig_host_src, &format!("-femit-bin={}", emit_bin), - "--mod", - &format!("glue::{}", find_zig_glue_path().to_str().unwrap()), - "--deps", - "glue", // include the zig runtime // "-fcompiler-rt", compiler-rt causes segfaults on windows; investigate why // include libc