WIP add script for zig platforms glue source

This commit is contained in:
Luke Boswell 2024-07-28 12:07:09 +10:00
parent a5d99668a8
commit 697bdb9262
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
4 changed files with 15 additions and 16 deletions

2
.gitignore vendored
View file

@ -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

5
copy-zig-glue-files.sh Normal file
View file

@ -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

View file

@ -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);

View file

@ -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