mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 16:44:33 +00:00
WIP add script for zig platforms glue source
This commit is contained in:
parent
a5d99668a8
commit
697bdb9262
4 changed files with 15 additions and 16 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -119,3 +119,5 @@ crates/glue/tests/fixtures/*/build.rs
|
||||||
crates/glue/tests/fixtures/*/host.c
|
crates/glue/tests/fixtures/*/host.c
|
||||||
crates/glue/tests/fixtures/*/src/main.rs
|
crates/glue/tests/fixtures/*/src/main.rs
|
||||||
crates/glue/tests/fixtures/*/test_glue/
|
crates/glue/tests/fixtures/*/test_glue/
|
||||||
|
|
||||||
|
**/platform/glue
|
||||||
|
|
5
copy-zig-glue-files.sh
Normal file
5
copy-zig-glue-files.sh
Normal 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
|
|
@ -1,6 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const str = @import("glue").str;
|
const str = @import("./glue/src/str.zig");
|
||||||
const RocStr = str.RocStr;
|
const RocStr = str.RocStr;
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const expectEqual = testing.expectEqual;
|
const expectEqual = testing.expectEqual;
|
||||||
|
@ -27,7 +27,7 @@ const DEBUG: bool = false;
|
||||||
|
|
||||||
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque {
|
export fn roc_alloc(size: usize, alignment: u32) callconv(.C) ?*anyopaque {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
var ptr = malloc(size);
|
const ptr = malloc(size);
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
stdout.print("alloc: {d} (alignment {d}, size {d})\n", .{ ptr, alignment, size }) catch unreachable;
|
stdout.print("alloc: {d} (alignment {d}, size {d})\n", .{ ptr, alignment, size }) catch unreachable;
|
||||||
return ptr;
|
return ptr;
|
||||||
|
@ -99,13 +99,13 @@ fn roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_
|
||||||
|
|
||||||
comptime {
|
comptime {
|
||||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||||
@export(roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong });
|
@export(roc_getppid, .{ .name = "roc_getppid", .linkage = .strong });
|
||||||
@export(roc_mmap, .{ .name = "roc_mmap", .linkage = .Strong });
|
@export(roc_mmap, .{ .name = "roc_mmap", .linkage = .strong });
|
||||||
@export(roc_shm_open, .{ .name = "roc_shm_open", .linkage = .Strong });
|
@export(roc_shm_open, .{ .name = "roc_shm_open", .linkage = .strong });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (builtin.os.tag == .windows) {
|
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
|
// 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 size = @max(@as(usize, @intCast(roc__mainForHost_1_exposed_size())), 8);
|
||||||
const raw_output = roc_alloc(@as(usize, @intCast(size)), @alignOf(u64)).?;
|
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 {
|
defer {
|
||||||
roc_dealloc(raw_output, @alignOf(u64));
|
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
|
// 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 size = @max(roc__mainForHost_0_result_size(), 8);
|
||||||
const raw_output = allocator.alignedAlloc(u8, @alignOf(u64), @as(usize, @intCast(size))) catch unreachable;
|
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 {
|
defer {
|
||||||
allocator.free(raw_output);
|
allocator.free(raw_output);
|
||||||
|
|
|
@ -171,10 +171,6 @@ pub fn build_zig_host_native(
|
||||||
zig_cmd.args([
|
zig_cmd.args([
|
||||||
zig_host_src,
|
zig_host_src,
|
||||||
&format!("-femit-bin={emit_bin}"),
|
&format!("-femit-bin={emit_bin}"),
|
||||||
"--mod",
|
|
||||||
&format!("glue::{}", find_zig_glue_path().to_str().unwrap()),
|
|
||||||
"--deps",
|
|
||||||
"glue",
|
|
||||||
// include libc
|
// include libc
|
||||||
"-lc",
|
"-lc",
|
||||||
// cross-compile?
|
// cross-compile?
|
||||||
|
@ -243,10 +239,6 @@ pub fn build_zig_host_native(
|
||||||
zig_cmd.args(&[
|
zig_cmd.args(&[
|
||||||
zig_host_src,
|
zig_host_src,
|
||||||
&format!("-femit-bin={}", emit_bin),
|
&format!("-femit-bin={}", emit_bin),
|
||||||
"--mod",
|
|
||||||
&format!("glue::{}", find_zig_glue_path().to_str().unwrap()),
|
|
||||||
"--deps",
|
|
||||||
"glue",
|
|
||||||
// include the zig runtime
|
// include the zig runtime
|
||||||
// "-fcompiler-rt", compiler-rt causes segfaults on windows; investigate why
|
// "-fcompiler-rt", compiler-rt causes segfaults on windows; investigate why
|
||||||
// include libc
|
// include libc
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue