From 18e95c710d40ebf4cb30750443ab9657774ff5e2 Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 21 Nov 2025 16:13:49 +0800 Subject: [PATCH 1/4] Specify Zig package in flake --- src/flake.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/flake.nix b/src/flake.nix index de7629441bb..7a83fa2d674 100644 --- a/src/flake.nix +++ b/src/flake.nix @@ -19,11 +19,13 @@ let pkgs = import nixpkgs { inherit system; }; - dependencies = (with pkgs; [ + zig=pkgs.zig_0_15; + + dependencies = [ zig - zls - git # for use in ci/zig_lints.sh - ]); + pkgs.zls + pkgs.git # for use in ci/zig_lints.sh + ]; shellFunctions = '' buildcmd() { @@ -54,7 +56,7 @@ shellHook = '' ${shellFunctions} - + echo "Some convenient commands:" echo "${shellFunctions}" | grep -E '^\s*[a-zA-Z_][a-zA-Z0-9_]*\(\)' | sed 's/().*//' | sed 's/^[[:space:]]*/ /' | while read func; do body=$(echo "${shellFunctions}" | sed -n "/''${func}()/,/^[[:space:]]*}/p" | sed '1d;$d' | tr '\n' ';' | sed 's/;$//' | sed 's/[[:space:]]*$//') From 709c04e36479876f01a40aef7776ad73dcc426ba Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 5 Nov 2025 12:47:28 +0800 Subject: [PATCH 2/4] Add Nix package to new Zig compiler --- src/flake.nix | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/flake.nix b/src/flake.nix index 7a83fa2d674..7f1d1cca6db 100644 --- a/src/flake.nix +++ b/src/flake.nix @@ -36,7 +36,7 @@ testcmd() { zig build snapshot && zig build test } - export -f testscmd + export -f testcmd fmtcmd() { zig build fmt @@ -50,6 +50,30 @@ ''; in { + packages = { + default = self.packages.${system}.roc; + roc = pkgs.stdenv.mkDerivation { + name = "roc"; + src = ../.; + nativeBuildInputs = [ zig.hook pkgs.pkg-config ]; + zigBuildFlags = [ "-Doptimize=ReleaseFast" ]; + + # NIX_CFLAGS_COMPILE=""; + # NIX_LDFLAGS=""; + }; + }; + + apps = { + default = self.apps.${system}.roc; + roc = { + type = "app"; + program = "${self.packages.${system}.roc}/bin/roc"; + meta = { + description = "Roc CLI"; + mainProgram = "roc"; + }; + }; + }; devShell = pkgs.mkShell { buildInputs = dependencies; From 31f1ec15a8b7ea3b543ebe6dadd9003da8c3756f Mon Sep 17 00:00:00 2001 From: Hannes Date: Wed, 5 Nov 2025 12:47:28 +0800 Subject: [PATCH 3/4] Add Nix build to CI --- .github/workflows/ci_zig.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci_zig.yml b/.github/workflows/ci_zig.yml index 5e21453e43c..d1d98053adc 100644 --- a/.github/workflows/ci_zig.yml +++ b/.github/workflows/ci_zig.yml @@ -249,6 +249,16 @@ jobs: git clean -fdx git reset --hard HEAD nix develop ./src/ -c zig build && zig build snapshot && zig build test + + - name: Test Nix package + if: ${{ runner.os == 'Linux' || (runner.os == 'macOS' && runner.arch != 'X64') }} + uses: ./.github/actions/flaky-retry + with: + command: | + nix build ./src#roc + result/bin/roc check src/PROFILING/bench_repeated_check.roc + error_string_contains: TemporaryNameServerFailure + retry_count: 3 zig-cross-compile: needs: check-once From 47d091e49f18b9e07b15ea8725b89f89d05342a4 Mon Sep 17 00:00:00 2001 From: Hannes Date: Mon, 1 Dec 2025 15:05:38 +0800 Subject: [PATCH 4/4] Add zig2nix --- .github/workflows/ci_zig.yml | 4 +- build.zig.zon | 22 ++-- build.zig.zon.nix | 217 +++++++++++++++++++++++++++++++++++ build.zig.zon2json-lock | 83 ++++++++++++++ flake.lock | 34 +++++- flake.nix | 33 +++++- src/flake.lock | 26 ++++- src/flake.nix | 30 ++++- 8 files changed, 422 insertions(+), 27 deletions(-) create mode 100644 build.zig.zon.nix create mode 100644 build.zig.zon2json-lock diff --git a/.github/workflows/ci_zig.yml b/.github/workflows/ci_zig.yml index d1d98053adc..2edda8d440c 100644 --- a/.github/workflows/ci_zig.yml +++ b/.github/workflows/ci_zig.yml @@ -255,7 +255,7 @@ jobs: uses: ./.github/actions/flaky-retry with: command: | - nix build ./src#roc + nix build .#roc result/bin/roc check src/PROFILING/bench_repeated_check.roc error_string_contains: TemporaryNameServerFailure retry_count: 3 @@ -292,4 +292,4 @@ jobs: # Test cross-compilation with Roc's cross-compilation system (musl + glibc) roc-cross-compile: - uses: ./.github/workflows/ci_cross_compile.yml \ No newline at end of file + uses: ./.github/workflows/ci_cross_compile.yml diff --git a/build.zig.zon b/build.zig.zon index d6472c94e0d..c1efb0bd8e1 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,47 +4,47 @@ .minimum_zig_version = "0.15.2", .dependencies = .{ .afl_kit = .{ - .url = "git+https://github.com/bhansconnect/zig-afl-kit?ref=main#b863c41ca47ed05729e0b509fb1926c111aa2800", - .hash = "afl_kit-0.1.0-NdJ3cncdAAA4154gtkRqNApovBYfOs-LWADNE-9BzzPC", + .url = "git+https://github.com/kristoff-it/zig-afl-kit.git#b6cb826f21d4026409caec30a932be462bca27b9", + .hash = "afl_kit-0.1.0-NdJ3cncdAADtO8S74G1yMYKO1f2XoHputmaJBInsHLp2", .lazy = true, }, .roc_deps_aarch64_macos_none = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-macos-none.tar.xz?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-macos-none.tar.xz", .hash = "N-V-__8AAJuttw4mNdQg3ig107ac4uyAhcFPznGHmpnmX58C", .lazy = true, }, .roc_deps_aarch64_linux_musl = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-linux-musl.tar.xz?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-linux-musl.tar.xz", .hash = "N-V-__8AABnBVRNhZGWHvWKm8PO-N4Js4Zr65NnswmkZ0nYX", .lazy = true, }, .roc_deps_aarch64_windows_gnu = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-windows-gnu.zip?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-windows-gnu.zip", .hash = "N-V-__8AAEbXoBTC007kkcMVW2_P5yIKMxPKQ-L5sYEc3_qH", .lazy = true, }, .roc_deps_arm_linux_musleabihf = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/arm-linux-musleabihf.tar.xz?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/arm-linux-musleabihf.tar.xz", .hash = "N-V-__8AAE9SyhMGHGnkgRenWYw-birLp2Nl-IYGqIbdlga3", .lazy = true, }, .roc_deps_x86_linux_musl = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86-linux-musl.tar.xz?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86-linux-musl.tar.xz", .hash = "N-V-__8AAGXNmxEQQYT5QBEheV2NJzSQjwaBuUx8wj_tGdoy", .lazy = true, }, .roc_deps_x86_64_linux_musl = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-linux-musl.tar.xz?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-linux-musl.tar.xz", .hash = "N-V-__8AAL1yjxS0Lef6Fv5mMGaqNa0rGcPJxOftYK0NYuJu", .lazy = true, }, .roc_deps_x86_64_macos_none = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-macos-none.tar.xz?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-macos-none.tar.xz", .hash = "N-V-__8AAInnSA9gFeMzlB67m7Nu-NYBUOXqDrzYmYgatUHk", .lazy = true, }, .roc_deps_x86_64_windows_gnu = .{ - .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-windows-gnu.zip?response-content-disposition=attachment", + .url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-windows-gnu.zip", .hash = "N-V-__8AANpEpBfszYPGDvz9XJK8VRBNG7eQzzK1iNSlkdVG", .lazy = true, }, @@ -54,7 +54,7 @@ }, .zstd = .{ .url = "git+https://github.com/allyourcodebase/zstd.git#01327d49cbc56dc24c20a167bb0055d7fc23de84", // 1.5.7 - .hash = "1220b9feb4652a62df95843e78a5db008401599366989b52d7cab421bf6263fa73d0", + .hash = "zstd-1.5.7-KEItkJ8vAAC5_rRlKmLflYQ-eKXbAIQBWZNmmJtS18q0", }, }, .fingerprint = 0x9eea22a6c3bd0034, diff --git a/build.zig.zon.nix b/build.zig.zon.nix new file mode 100644 index 00000000000..38aaec34584 --- /dev/null +++ b/build.zig.zon.nix @@ -0,0 +1,217 @@ +# generated by zon2nix (https://github.com/Cloudef/zig2nix) + +{ + lib, + linkFarm, + fetchurl, + fetchgit, + runCommandLocal, + zig, + name ? "zig-packages", +}: + +with builtins; +with lib; + +let + unpackZigArtifact = + { name, artifact }: + runCommandLocal name { nativeBuildInputs = [ zig ]; } '' + hash="$(zig fetch --global-cache-dir "$TMPDIR" ${artifact})" + mv "$TMPDIR/p/$hash" "$out" + chmod 755 "$out" + ''; + + fetchZig = + { + name, + url, + hash, + }: + let + artifact = fetchurl { inherit url hash; }; + in + unpackZigArtifact { inherit name artifact; }; + + fetchGitZig = + { + name, + url, + hash, + rev ? throw "rev is required, remove and regenerate the zon2json-lock file", + }: + let + parts = splitString "#" url; + url_base = elemAt parts 0; + url_without_query = elemAt (splitString "?" url_base) 0; + in + fetchgit { + inherit name rev hash; + url = url_without_query; + deepClone = false; + }; + + fetchZigArtifact = + { + name, + url, + hash, + ... + }@args: + let + parts = splitString "://" url; + proto = elemAt parts 0; + path = elemAt parts 1; + fetcher = { + "git+http" = fetchGitZig ( + args + // { + url = "http://${path}"; + } + ); + "git+https" = fetchGitZig ( + args + // { + url = "https://${path}"; + } + ); + http = fetchZig { + inherit name hash; + url = "http://${path}"; + }; + https = fetchZig { + inherit name hash; + url = "https://${path}"; + }; + }; + in + fetcher.${proto}; +in +linkFarm name [ + { + name = "afl_kit-0.1.0-NdJ3cncdAADtO8S74G1yMYKO1f2XoHputmaJBInsHLp2"; + path = fetchZigArtifact { + name = "afl_kit"; + url = "git+https://github.com/kristoff-it/zig-afl-kit.git#b6cb826f21d4026409caec30a932be462bca27b9"; + hash = "sha256-b3aBfO1aiM9MV6Pqdy0A8xbRy/X9zEJCztXMe18k2rA="; + rev = "b6cb826f21d4026409caec30a932be462bca27b9"; + }; + } + { + name = "AFLplusplus-4.21.0-aA1y4dZxAAAhqDy_JoRw3zwNSg8MenEGP7uJI_xNcYuV"; + path = fetchZigArtifact { + name = "AFLplusplus"; + url = "git+https://github.com/allyourcodebase/AFLplusplus#7e65eb4262688a120bf830d145060aac0e5db920"; + hash = "sha256-f5Egmkg2tEOV5jfcNj9KTU0IWOAC/hGdypmC+IG88Q0="; + rev = "7e65eb4262688a120bf830d145060aac0e5db920"; + }; + } + { + name = "N-V-__8AAKE4uAAJZgEcPdaXnWqoj-IwYf3G2h9YSm-x92gg"; + path = fetchZigArtifact { + name = "AFLplusplus"; + url = "https://github.com/AFLplusplus/AFLplusplus/archive/v4.21c.tar.gz"; + hash = "sha256-EffHfTfP9uf2WsfMVbq3kB4MYgjoRaOHZDlNBO1WezA="; + }; + } + { + name = "N-V-__8AAJuttw4mNdQg3ig107ac4uyAhcFPznGHmpnmX58C"; + path = fetchZigArtifact { + name = "roc_deps_aarch64_macos_none"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-macos-none.tar.xz"; + hash = "sha256-V5vrynGlea56TSLjNpkVpQFJID+d/U/yMaflwNSQaQU="; + }; + } + { + name = "N-V-__8AABnBVRNhZGWHvWKm8PO-N4Js4Zr65NnswmkZ0nYX"; + path = fetchZigArtifact { + name = "roc_deps_aarch64_linux_musl"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-linux-musl.tar.xz"; + hash = "sha256-CXGVG1A7V/xhpu1Kgv6RtF7EH0xKXlVXWVLOfx8DptA="; + }; + } + { + name = "N-V-__8AAEbXoBTC007kkcMVW2_P5yIKMxPKQ-L5sYEc3_qH"; + path = fetchZigArtifact { + name = "roc_deps_aarch64_windows_gnu"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-windows-gnu.zip"; + hash = "sha256-LbVIeMh8gguUczU7nDqOhmkPlSXIYU5kH6EhcssjpWY="; + }; + } + { + name = "N-V-__8AAE9SyhMGHGnkgRenWYw-birLp2Nl-IYGqIbdlga3"; + path = fetchZigArtifact { + name = "roc_deps_arm_linux_musleabihf"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/arm-linux-musleabihf.tar.xz"; + hash = "sha256-0fw/KOpzj7OSgFrysfRGv4WlU/JvaaC3xXu6V+LyEs8="; + }; + } + { + name = "N-V-__8AAGXNmxEQQYT5QBEheV2NJzSQjwaBuUx8wj_tGdoy"; + path = fetchZigArtifact { + name = "roc_deps_x86_linux_musl"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86-linux-musl.tar.xz"; + hash = "sha256-LyYtnADq9CmmzRH+qu3WPRHPj2LjY3zszlyCB+CiRAo="; + }; + } + { + name = "N-V-__8AAL1yjxS0Lef6Fv5mMGaqNa0rGcPJxOftYK0NYuJu"; + path = fetchZigArtifact { + name = "roc_deps_x86_64_linux_musl"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-linux-musl.tar.xz"; + hash = "sha256-zmrzXp9790M4NfjFuBU+TZ7jWjJdN+Z1vRs9aKwkmJM="; + }; + } + { + name = "N-V-__8AAInnSA9gFeMzlB67m7Nu-NYBUOXqDrzYmYgatUHk"; + path = fetchZigArtifact { + name = "roc_deps_x86_64_macos_none"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-macos-none.tar.xz"; + hash = "sha256-w3vpIPXWlmIRztbXPGXiemrwYF9jjFIaFxpZaLOZ9KI="; + }; + } + { + name = "N-V-__8AANpEpBfszYPGDvz9XJK8VRBNG7eQzzK1iNSlkdVG"; + path = fetchZigArtifact { + name = "roc_deps_x86_64_windows_gnu"; + url = "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-windows-gnu.zip"; + hash = "sha256-tckuUDxjoeAUWC5RiHW1IVKG3H67R1D0cONk93VbkLs="; + }; + } + { + name = "bytebox-0.0.1-SXc2seA2DwAUHbrqTMz_mAQQGqO0EVPYmZ89YZn4KsTi"; + path = fetchZigArtifact { + name = "bytebox"; + url = "git+https://github.com/rdunnington/bytebox#5c8753ba11c394e4d642dddbb459edcd7c97ac26"; + hash = "sha256-UMXzrH5OPqQmt5B2hlMkKzSa1gjI2EreDRK9Son+ZvM="; + rev = "5c8753ba11c394e4d642dddbb459edcd7c97ac26"; + }; + } + { + name = "stable_array-0.1.0-3ihgvVxbAACET5MoiUn2T5ENunG_da_X3kGbji-f4QTF"; + path = fetchZigArtifact { + name = "zig-stable-array"; + url = "git+https://github.com/rdunnington/zig-stable-array#9e4f089bd3abf127eafd307ecf9796455871becc"; + hash = "sha256-NpxyNyOoFAeyREn3SvEnI/tyaYgM1ZjlcK+0jG2N0Lk="; + rev = "9e4f089bd3abf127eafd307ecf9796455871becc"; + }; + } + { + name = "zstd-1.5.7-KEItkJ8vAAC5_rRlKmLflYQ-eKXbAIQBWZNmmJtS18q0"; + path = fetchZigArtifact { + name = "zstd"; + url = "git+https://github.com/allyourcodebase/zstd.git#01327d49cbc56dc24c20a167bb0055d7fc23de84"; + hash = "sha256-1w+hR2U9t6R4sNvUMynDsYO0sNAan2svjxjUvxT+x6A="; + rev = "01327d49cbc56dc24c20a167bb0055d7fc23de84"; + }; + } + { + name = "N-V-__8AAGxifwAAGwXwvsnl_aOXFGLZTeYCu0WBhuEXr96u"; + path = fetchZigArtifact { + name = "zstd"; + url = "git+https://github.com/facebook/zstd.git?ref=v1.5.7#f8745da6ff1ad1e7bab384bd1f9d742439278e99"; + hash = "sha256-tNFWIT9ydfozB8dWcmTMuZLCQmQudTFJIkSr0aG7S44="; + rev = "f8745da6ff1ad1e7bab384bd1f9d742439278e99"; + }; + } +] diff --git a/build.zig.zon2json-lock b/build.zig.zon2json-lock new file mode 100644 index 00000000000..35e27894d4e --- /dev/null +++ b/build.zig.zon2json-lock @@ -0,0 +1,83 @@ +{ + "afl_kit-0.1.0-NdJ3cncdAADtO8S74G1yMYKO1f2XoHputmaJBInsHLp2": { + "name": "afl_kit", + "url": "git+https://github.com/kristoff-it/zig-afl-kit.git#b6cb826f21d4026409caec30a932be462bca27b9", + "hash": "sha256-b3aBfO1aiM9MV6Pqdy0A8xbRy/X9zEJCztXMe18k2rA=", + "rev": "b6cb826f21d4026409caec30a932be462bca27b9" + }, + "AFLplusplus-4.21.0-aA1y4dZxAAAhqDy_JoRw3zwNSg8MenEGP7uJI_xNcYuV": { + "name": "AFLplusplus", + "url": "git+https://github.com/allyourcodebase/AFLplusplus#7e65eb4262688a120bf830d145060aac0e5db920", + "hash": "sha256-f5Egmkg2tEOV5jfcNj9KTU0IWOAC/hGdypmC+IG88Q0=", + "rev": "7e65eb4262688a120bf830d145060aac0e5db920" + }, + "N-V-__8AAKE4uAAJZgEcPdaXnWqoj-IwYf3G2h9YSm-x92gg": { + "name": "AFLplusplus", + "url": "https://github.com/AFLplusplus/AFLplusplus/archive/v4.21c.tar.gz", + "hash": "sha256-EffHfTfP9uf2WsfMVbq3kB4MYgjoRaOHZDlNBO1WezA=" + }, + "N-V-__8AAJuttw4mNdQg3ig107ac4uyAhcFPznGHmpnmX58C": { + "name": "roc_deps_aarch64_macos_none", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-macos-none.tar.xz", + "hash": "sha256-V5vrynGlea56TSLjNpkVpQFJID+d/U/yMaflwNSQaQU=" + }, + "N-V-__8AABnBVRNhZGWHvWKm8PO-N4Js4Zr65NnswmkZ0nYX": { + "name": "roc_deps_aarch64_linux_musl", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-linux-musl.tar.xz", + "hash": "sha256-CXGVG1A7V/xhpu1Kgv6RtF7EH0xKXlVXWVLOfx8DptA=" + }, + "N-V-__8AAEbXoBTC007kkcMVW2_P5yIKMxPKQ-L5sYEc3_qH": { + "name": "roc_deps_aarch64_windows_gnu", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/aarch64-windows-gnu.zip", + "hash": "sha256-LbVIeMh8gguUczU7nDqOhmkPlSXIYU5kH6EhcssjpWY=" + }, + "N-V-__8AAE9SyhMGHGnkgRenWYw-birLp2Nl-IYGqIbdlga3": { + "name": "roc_deps_arm_linux_musleabihf", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/arm-linux-musleabihf.tar.xz", + "hash": "sha256-0fw/KOpzj7OSgFrysfRGv4WlU/JvaaC3xXu6V+LyEs8=" + }, + "N-V-__8AAGXNmxEQQYT5QBEheV2NJzSQjwaBuUx8wj_tGdoy": { + "name": "roc_deps_x86_linux_musl", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86-linux-musl.tar.xz", + "hash": "sha256-LyYtnADq9CmmzRH+qu3WPRHPj2LjY3zszlyCB+CiRAo=" + }, + "N-V-__8AAL1yjxS0Lef6Fv5mMGaqNa0rGcPJxOftYK0NYuJu": { + "name": "roc_deps_x86_64_linux_musl", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-linux-musl.tar.xz", + "hash": "sha256-zmrzXp9790M4NfjFuBU+TZ7jWjJdN+Z1vRs9aKwkmJM=" + }, + "N-V-__8AAInnSA9gFeMzlB67m7Nu-NYBUOXqDrzYmYgatUHk": { + "name": "roc_deps_x86_64_macos_none", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-macos-none.tar.xz", + "hash": "sha256-w3vpIPXWlmIRztbXPGXiemrwYF9jjFIaFxpZaLOZ9KI=" + }, + "N-V-__8AANpEpBfszYPGDvz9XJK8VRBNG7eQzzK1iNSlkdVG": { + "name": "roc_deps_x86_64_windows_gnu", + "url": "https://github.com/roc-lang/roc-bootstrap/releases/download/zig-0.15.1/x86_64-windows-gnu.zip", + "hash": "sha256-tckuUDxjoeAUWC5RiHW1IVKG3H67R1D0cONk93VbkLs=" + }, + "bytebox-0.0.1-SXc2seA2DwAUHbrqTMz_mAQQGqO0EVPYmZ89YZn4KsTi": { + "name": "bytebox", + "url": "git+https://github.com/rdunnington/bytebox#5c8753ba11c394e4d642dddbb459edcd7c97ac26", + "hash": "sha256-UMXzrH5OPqQmt5B2hlMkKzSa1gjI2EreDRK9Son+ZvM=", + "rev": "5c8753ba11c394e4d642dddbb459edcd7c97ac26" + }, + "stable_array-0.1.0-3ihgvVxbAACET5MoiUn2T5ENunG_da_X3kGbji-f4QTF": { + "name": "zig-stable-array", + "url": "git+https://github.com/rdunnington/zig-stable-array#9e4f089bd3abf127eafd307ecf9796455871becc", + "hash": "sha256-NpxyNyOoFAeyREn3SvEnI/tyaYgM1ZjlcK+0jG2N0Lk=", + "rev": "9e4f089bd3abf127eafd307ecf9796455871becc" + }, + "zstd-1.5.7-KEItkJ8vAAC5_rRlKmLflYQ-eKXbAIQBWZNmmJtS18q0": { + "name": "zstd", + "url": "git+https://github.com/allyourcodebase/zstd.git#01327d49cbc56dc24c20a167bb0055d7fc23de84", + "hash": "sha256-1w+hR2U9t6R4sNvUMynDsYO0sNAan2svjxjUvxT+x6A=", + "rev": "01327d49cbc56dc24c20a167bb0055d7fc23de84" + }, + "N-V-__8AAGxifwAAGwXwvsnl_aOXFGLZTeYCu0WBhuEXr96u": { + "name": "zstd", + "url": "git+https://github.com/facebook/zstd.git?ref=v1.5.7#f8745da6ff1ad1e7bab384bd1f9d742439278e99", + "hash": "sha256-tNFWIT9ydfozB8dWcmTMuZLCQmQudTFJIkSr0aG7S44=", + "rev": "f8745da6ff1ad1e7bab384bd1f9d742439278e99" + } +} \ No newline at end of file diff --git a/flake.lock b/flake.lock index f3968fd31ef..526a8b6a264 100644 --- a/flake.lock +++ b/flake.lock @@ -36,17 +36,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1722403750, - "narHash": "sha256-tRmn6UiFAPX0m9G1AVcEPjWEOc9BtGsxGcs7Bz3MpsM=", + "lastModified": 1764517877, + "narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "184957277e885c06a505db112b35dfbec7c60494", + "rev": "2d293cbfa5a793b4c50d17c05ef9e385b90edf6c", "type": "github" }, "original": { "owner": "nixos", + "ref": "nixos-unstable", "repo": "nixpkgs", - "rev": "184957277e885c06a505db112b35dfbec7c60494", "type": "github" } }, @@ -55,7 +55,8 @@ "flake-compat": "flake-compat", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" + "rust-overlay": "rust-overlay", + "zig2nix": "zig2nix" } }, "rust-overlay": { @@ -92,6 +93,29 @@ "repo": "default", "type": "github" } + }, + "zig2nix": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1764640229, + "narHash": "sha256-yv6lORKN929oN4oh/Lg3SWnJXpjZmYJNcn4pqS2+miE=", + "owner": "Cloudef", + "repo": "zig2nix", + "rev": "b0a62933411024cc283548476ea6a0dce0ffcbcf", + "type": "github" + }, + "original": { + "owner": "Cloudef", + "repo": "zig2nix", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 9ae6ac0b78a..1ff5d1084c5 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ inputs = { nixpkgs.url = - "github:nixos/nixpkgs?rev=184957277e885c06a505db112b35dfbec7c60494"; + "github:nixos/nixpkgs/nixos-unstable"; # rust from nixpkgs has some libc problems, this is patched in the rust-overlay rust-overlay = { @@ -18,9 +18,15 @@ url = "github:edolstra/flake-compat"; flake = false; }; + + zig2nix = { + url = "github:Cloudef/zig2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; }; - outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }@inputs: + outputs = { self, nixpkgs, rust-overlay, flake-utils,zig2nix, ... }@inputs: let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ]; @@ -152,6 +158,29 @@ lang-server = rocBuild.roc-lang-server; lang-server-debug = rocBuild.roc-lang-server-debug; + + roc = let pkgs = import nixpkgs { inherit system; }; + zig=pkgs.zig_0_15; + env = zig2nix.outputs.zig-env.${system} { + nixpkgs = nixpkgs;zig=zig; + }; + in env.package { + # name = "roc"; + src = pkgs.lib.cleanSource ./.; + nativeBuildInputs = []; + buildInputs = []; + # zigPreferMusl = false; + zigPreferMusl = true; # Smaller binaries and avoids shipping glibc. + zigBuildZon=./build.zig.zon; + zigBuildZonLock = ./build.zig.zon2json-lock; + # nativeBuildInputs = [ zig.hook pkgs.pkg-config ]; + zigBuildFlags = [ "-Doptimize=ReleaseFast" ]; + + # NIX_CFLAGS_COMPILE=""; + # NIX_LDFLAGS=""; + + meta.mainProgram="roc"; + }; }; apps = { diff --git a/src/flake.lock b/src/flake.lock index 5b83b57293d..66b4441b384 100644 --- a/src/flake.lock +++ b/src/flake.lock @@ -37,7 +37,8 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "zig2nix": "zig2nix" } }, "systems": { @@ -54,6 +55,29 @@ "repo": "default", "type": "github" } + }, + "zig2nix": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1745026949, + "narHash": "sha256-P+6DKKaZniG5xJIzKpZ7Kt5qdn3RCuFDDo2Atr0y5NU=", + "owner": "Cloudef", + "repo": "zig2nix", + "rev": "d8730240de15020f8022b23d7d6d2fbb53cdae6d", + "type": "github" + }, + "original": { + "owner": "Cloudef", + "repo": "zig2nix", + "type": "github" + } } }, "root": "root", diff --git a/src/flake.nix b/src/flake.nix index 7f1d1cca6db..c357adf084f 100644 --- a/src/flake.nix +++ b/src/flake.nix @@ -9,15 +9,25 @@ # to easily make configs for multiple architectures flake-utils.url = "github:numtide/flake-utils"; + + zig2nix = { + url = "github:Cloudef/zig2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; }; - outputs = { self, nixpkgs, flake-utils, ... }@inputs: + outputs = { self, nixpkgs, flake-utils,zig2nix, ... }@inputs: let supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ]; + in flake-utils.lib.eachSystem supportedSystems (system: let pkgs = import nixpkgs { inherit system; }; + env = zig2nix.outputs.zig-env.${system} { + nixpkgs = nixpkgs;zig=zig; + }; zig=pkgs.zig_0_15; @@ -52,14 +62,22 @@ in { packages = { default = self.packages.${system}.roc; - roc = pkgs.stdenv.mkDerivation { - name = "roc"; - src = ../.; - nativeBuildInputs = [ zig.hook pkgs.pkg-config ]; + roc = env.package { + # name = "roc"; + src = ./..; + nativeBuildInputs = []; + buildInputs = []; + # zigPreferMusl = false; + zigPreferMusl = true; # Smaller binaries and avoids shipping glibc. + zigBuildZon=../build.zig.zon; + zigBuildZonLock = ../build.zig.zon2json-lock; + # nativeBuildInputs = [ zig.hook pkgs.pkg-config ]; zigBuildFlags = [ "-Doptimize=ReleaseFast" ]; # NIX_CFLAGS_COMPILE=""; # NIX_LDFLAGS=""; + + meta.mainProgram="roc"; }; }; @@ -67,7 +85,7 @@ default = self.apps.${system}.roc; roc = { type = "app"; - program = "${self.packages.${system}.roc}/bin/roc"; + program = pkgs.lib.getExe self.packages.${system}.roc ; meta = { description = "Roc CLI"; mainProgram = "roc";