From f4451722e8d045c089de9006fb433d4558972b11 Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Wed, 13 Nov 2024 09:02:37 +1100 Subject: [PATCH] Merge remote/main into upgrade branch --- .gitignore | 2 ++ Cargo.lock | 4 ++- crates/cli/Cargo.toml | 1 + crates/cli/tests/cli_tests.rs | 8 +++++ .../multiple_exposed/platform/host.zig | 2 +- .../tests/test-projects/tui/platform/host.zig | 14 ++++---- crates/compiler/can/Cargo.toml | 2 +- crates/compiler/collections/Cargo.toml | 2 +- crates/compiler/constrain/Cargo.toml | 3 +- crates/compiler/parse/Cargo.toml | 3 +- crates/compiler/solve/Cargo.toml | 2 +- crates/compiler/types/Cargo.toml | 3 +- crates/copy_zig_glue/src/lib.rs | 32 ++++++++++++------- crates/valgrind_tests/Cargo.toml | 1 + crates/valgrind_tests/src/lib.rs | 2 ++ examples/cli/effects-platform/Effect.roc | 7 ---- flake.lock | 6 ++-- 17 files changed, 55 insertions(+), 39 deletions(-) delete mode 100644 examples/cli/effects-platform/Effect.roc diff --git a/.gitignore b/.gitignore index b88dc2bcd8..a73175461e 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,5 @@ crates/glue/tests/fixtures/*/test_glue/ # ignore the zig glue files copied into test platforms **/*platform/glue/* +crates/cli/tests/test-projects/test-platform-effects-zig/glue +crates/cli/tests/test-projects/test-platform-simple-zig/glue diff --git a/Cargo.lock b/Cargo.lock index 708c497cd2..c71b7a69bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -473,8 +473,8 @@ name = "cli_test_utils" version = "0.0.1" dependencies = [ "bumpalo", - "copy_zig_glue", "const_format", + "copy_zig_glue", "criterion", "lazy_static", "regex", @@ -2408,6 +2408,7 @@ dependencies = [ "clap 4.4.6", "cli_test_utils", "const_format", + "copy_zig_glue", "criterion", "distance", "errno", @@ -4373,6 +4374,7 @@ version = "0.0.1" dependencies = [ "bumpalo", "cli_test_utils", + "copy_zig_glue", "indoc", "roc_build", "roc_command_utils", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 44448f3114..08646444af 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -65,6 +65,7 @@ roc_reporting = { path = "../reporting" } roc_target = { path = "../compiler/roc_target" } roc_tracing = { path = "../tracing" } roc_wasm_interp = { path = "../wasm_interp", optional = true } +copy_zig_glue = { path = "../copy_zig_glue" } ven_pretty = { path = "../vendor/pretty" } diff --git a/crates/cli/tests/cli_tests.rs b/crates/cli/tests/cli_tests.rs index 9a77c58f91..a3b988e4dc 100644 --- a/crates/cli/tests/cli_tests.rs +++ b/crates/cli/tests/cli_tests.rs @@ -184,6 +184,8 @@ mod cli_tests { #[cfg_attr(windows, ignore)] // tea = The Elm Architecture fn terminal_ui_tea() { + copy_zig_glue::initialize_zig_test_platforms(); + let cli_build = ExecCli::new( CMD_BUILD, file_from_root("crates/cli/tests/test-projects/tui", "main.roc"), @@ -266,6 +268,8 @@ mod cli_tests { #[test] #[cfg_attr(windows, ignore)] fn multiple_exposed() { + copy_zig_glue::initialize_zig_test_platforms(); + let cli_build = ExecCli::new( CMD_BUILD, file_from_root( @@ -461,6 +465,8 @@ mod cli_tests { /// Build the platform host once for all tests in this module fn build_platform_host() { BUILD_PLATFORM_HOST.call_once(|| { + copy_zig_glue::initialize_zig_test_platforms(); + let cli_build = ExecCli::new( CMD_BUILD, file_from_root( @@ -800,6 +806,8 @@ mod cli_tests { /// Build the platform host once for all tests in this module fn build_platform_host() { BUILD_PLATFORM_HOST.call_once(|| { + copy_zig_glue::initialize_zig_test_platforms(); + let cli_build = ExecCli::new( CMD_BUILD, file_from_root( diff --git a/crates/cli/tests/test-projects/multiple_exposed/platform/host.zig b/crates/cli/tests/test-projects/multiple_exposed/platform/host.zig index 6b5e7053e5..5ab48472ce 100644 --- a/crates/cli/tests/test-projects/multiple_exposed/platform/host.zig +++ b/crates/cli/tests/test-projects/multiple_exposed/platform/host.zig @@ -24,7 +24,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; diff --git a/crates/cli/tests/test-projects/tui/platform/host.zig b/crates/cli/tests/test-projects/tui/platform/host.zig index 063336b8fd..b3e6da41e5 100644 --- a/crates/cli/tests/test-projects/tui/platform/host.zig +++ b/crates/cli/tests/test-projects/tui/platform/host.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const str = @import("glue").str; +const str = @import("glue/str.zig"); const RocStr = str.RocStr; const testing = std.testing; const expectEqual = testing.expectEqual; @@ -25,7 +25,7 @@ extern fn roc__mainForHost_0_result_size() i64; fn allocate_model(allocator: *Allocator) MutModel { const size = roc__mainForHost_0_result_size(); 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)); return output; } @@ -86,7 +86,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; @@ -158,13 +158,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 }); } } diff --git a/crates/compiler/can/Cargo.toml b/crates/compiler/can/Cargo.toml index 12ff46d750..9a8a4ad3f6 100644 --- a/crates/compiler/can/Cargo.toml +++ b/crates/compiler/can/Cargo.toml @@ -24,7 +24,7 @@ bitvec.workspace = true bumpalo.workspace = true static_assertions.workspace = true -soa.workspace = true +soa = { path = "../../soa" } [dev-dependencies] indoc.workspace = true diff --git a/crates/compiler/collections/Cargo.toml b/crates/compiler/collections/Cargo.toml index fd26c75bde..5c3ddbf81a 100644 --- a/crates/compiler/collections/Cargo.toml +++ b/crates/compiler/collections/Cargo.toml @@ -17,4 +17,4 @@ im.workspace = true wyhash.workspace = true smallvec.workspace = true -soa.workspace = true +soa = { path = "../../soa" } diff --git a/crates/compiler/constrain/Cargo.toml b/crates/compiler/constrain/Cargo.toml index ab750ac677..6e1d17b48b 100644 --- a/crates/compiler/constrain/Cargo.toml +++ b/crates/compiler/constrain/Cargo.toml @@ -16,7 +16,6 @@ roc_parse = { path = "../parse" } roc_problem = { path = "../problem" } roc_region = { path = "../region" } roc_types = { path = "../types" } +soa = { path = "../../soa" } arrayvec.workspace = true - -soa.workspace = true diff --git a/crates/compiler/parse/Cargo.toml b/crates/compiler/parse/Cargo.toml index e4c137f997..23c164b62a 100644 --- a/crates/compiler/parse/Cargo.toml +++ b/crates/compiler/parse/Cargo.toml @@ -15,8 +15,7 @@ roc_collections = { path = "../collections" } roc_module = { path = "../module" } roc_region = { path = "../region" } roc_error_macros = { path = "../../error_macros" } - -soa.workspace = true +soa = { path = "../../soa" } bumpalo.workspace = true encode_unicode.workspace = true diff --git a/crates/compiler/solve/Cargo.toml b/crates/compiler/solve/Cargo.toml index 19ba538961..e9bc7fc332 100644 --- a/crates/compiler/solve/Cargo.toml +++ b/crates/compiler/solve/Cargo.toml @@ -23,11 +23,11 @@ roc_solve_problem = { path = "../solve_problem" } roc_solve_schema = { path = "../solve_schema" } roc_types = { path = "../types" } roc_unify = { path = "../unify" } +soa = { path = "../../soa" } arrayvec.workspace = true bumpalo.workspace = true -soa.workspace = true [dev-dependencies] roc_builtins = { path = "../builtins" } diff --git a/crates/compiler/types/Cargo.toml b/crates/compiler/types/Cargo.toml index 41ed2ca595..2d459709f7 100644 --- a/crates/compiler/types/Cargo.toml +++ b/crates/compiler/types/Cargo.toml @@ -15,10 +15,9 @@ roc_module = { path = "../module" } roc_region = { path = "../region" } roc_serialize = { path = "../serialize" } roc_parse = { path = "../parse" } +soa = { path = "../../soa" } ven_pretty = { path = "../../vendor/pretty" } bumpalo.workspace = true static_assertions.workspace = true - -soa.workspace = true diff --git a/crates/copy_zig_glue/src/lib.rs b/crates/copy_zig_glue/src/lib.rs index e7f44661e3..52fdc74580 100644 --- a/crates/copy_zig_glue/src/lib.rs +++ b/crates/copy_zig_glue/src/lib.rs @@ -1,7 +1,19 @@ use std::path::Path; +use std::path::PathBuf; +use std::sync::Once; use std::{fs, io}; -use std::path::PathBuf; +static ZIG_PLATFORM_COPY_GLUE_ONCE: Once = Once::new(); + +/// Copies the glue source files for zig platforms from the roc builtins +/// this is only temporary, see comments in crates/copy_zig_glue/src/main.rs +pub fn initialize_zig_test_platforms() { + ZIG_PLATFORM_COPY_GLUE_ONCE.call_once(|| { + dbg!("ZIG_PLATFORM_COPY_GLUE_ONCE"); + // initialization code here + copy_zig_glue(); + }); +} /// Copy the zig builtins source files into each of the test platform folders. /// @@ -16,18 +28,16 @@ pub fn copy_zig_glue() { let zig_builtins_source_dir = workspace_dir.join("crates/compiler/builtins/bitcode/src"); let zig_test_platforms_dirs: Vec = vec![ - workspace_dir.join("crates/cli/tests/platform_requires_pkg/platform/glue"), - workspace_dir.join("crates/cli/tests/algorithms/fibonacci-platform/glue"), - workspace_dir.join("crates/cli/tests/algorithms/quicksort-platform/glue"), + workspace_dir.join("crates/cli/tests/test-projects/platform_requires_pkg/platform/glue"), + workspace_dir.join("crates/cli/tests/test-projects/algorithms/fibonacci-platform/glue"), + workspace_dir.join("crates/cli/tests/test-projects/algorithms/quicksort-platform/glue"), workspace_dir.join("crates/cli/tests/benchmarks/platform/glue"), - workspace_dir.join("crates/cli/tests/expects/zig-platform/glue"), - workspace_dir.join("crates/cli/tests/fixtures/multi-dep-str/platform/glue"), - workspace_dir.join("crates/cli/tests/fixtures/multi-dep-thunk/platform/glue"), - workspace_dir.join("crates/cli/tests/fixtures/packages/platform/glue"), - workspace_dir.join("crates/valgrind/zig-platform/glue"), - workspace_dir.join("examples/cli/effects-platform/glue"), - workspace_dir.join("examples/cli/tui-platform/glue"), + workspace_dir.join("crates/valgrind_tests/zig-platform/glue"), + workspace_dir.join("crates/cli/tests/test-projects/test-platform-effects-zig/glue"), + workspace_dir.join("crates/cli/tests/test-projects/test-platform-simple-zig/glue"), workspace_dir.join("examples/platform-switching/zig-platform/glue"), + workspace_dir.join("crates/cli/tests/test-projects/multiple_exposed/platform/glue"), + workspace_dir.join("crates/cli/tests/test-projects/tui/platform/glue"), ]; for target_dir in zig_test_platforms_dirs { diff --git a/crates/valgrind_tests/Cargo.toml b/crates/valgrind_tests/Cargo.toml index eaa26f989f..fa6d1ca859 100644 --- a/crates/valgrind_tests/Cargo.toml +++ b/crates/valgrind_tests/Cargo.toml @@ -15,6 +15,7 @@ roc_load = { path = "../compiler/load" } roc_mono = { path = "../compiler/mono" } roc_packaging = { path = "../packaging" } roc_reporting = { path = "../reporting" } +copy_zig_glue = { path = "../copy_zig_glue" } bumpalo.workspace = true indoc.workspace = true diff --git a/crates/valgrind_tests/src/lib.rs b/crates/valgrind_tests/src/lib.rs index 4df9cca9d5..f0106b214e 100644 --- a/crates/valgrind_tests/src/lib.rs +++ b/crates/valgrind_tests/src/lib.rs @@ -61,6 +61,8 @@ fn build_host() { } fn valgrind_test(source: &str) { + copy_zig_glue::initialize_zig_test_platforms(); + #[cfg(target_os = "linux")] { valgrind_test_linux(source) diff --git a/examples/cli/effects-platform/Effect.roc b/examples/cli/effects-platform/Effect.roc deleted file mode 100644 index 8b1ab6d69f..0000000000 --- a/examples/cli/effects-platform/Effect.roc +++ /dev/null @@ -1,7 +0,0 @@ -hosted Effect - exposes [putLine!, getLine!] - imports [] - -putLine! : Str => {} - -getLine! : {} => Str diff --git a/flake.lock b/flake.lock index a792d895f6..c060665dd6 100644 --- a/flake.lock +++ b/flake.lock @@ -89,11 +89,11 @@ ] }, "locked": { - "lastModified": 1727490462, - "narHash": "sha256-OrrPiNBiikv9BR464XTT75FzOq7tKAvMbMi7YOKVIeg=", + "lastModified": 1731378398, + "narHash": "sha256-a0QWaiX8+AJ9/XBLGMDy6c90GD7HzpxKVdlFwCke5Pw=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "11a13e50debafae4ae802f1d6b8585101516dd93", + "rev": "0ae9fc2f2fe5361837d59c0bdebbda176427111e", "type": "github" }, "original": {