diff --git a/nixos/doc/manual/release-notes/rl-2411.section.md b/nixos/doc/manual/release-notes/rl-2411.section.md index 51904352b3b7..cb8eb6dfb3be 100644 --- a/nixos/doc/manual/release-notes/rl-2411.section.md +++ b/nixos/doc/manual/release-notes/rl-2411.section.md @@ -46,6 +46,10 @@ +- `hareHook` has been added as the language framework for Hare. From now on, it, + not the `hare` package, should be added to `nativeBuildInputs` when building + Hare programs. + - To facilitate dependency injection, the `imgui` package now builds a static archive using vcpkg' CMake rules. The derivation now installs "impl" headers selectively instead of by a wildcard. Use `imgui.src` if you just want to access the unpacked sources. diff --git a/pkgs/by-name/ha/hare/hook.nix b/pkgs/by-name/ha/hare/hook.nix new file mode 100644 index 000000000000..e5a9bad131aa --- /dev/null +++ b/pkgs/by-name/ha/hare/hook.nix @@ -0,0 +1,56 @@ +{ + hare, + lib, + makeSetupHook, + makeWrapper, + runCommand, + stdenv, + writeShellApplication, +}: +let + arch = stdenv.targetPlatform.uname.processor; + harePropagationInputs = builtins.attrValues { inherit (hare) harec qbe; }; + hareWrappedScript = writeShellApplication { + # `name` MUST be `hare`, since its role is to replace the hare binary. + name = "hare"; + runtimeInputs = [ hare ]; + excludeShellChecks = [ "SC2086" ]; + # ''${cmd:+"$cmd"} is used on the default case to keep the same behavior as + # the hare binary: If "$cmd" is passed directly and it's empty, the hare + # binary will treat it as an unrecognized command. + text = '' + readonly cmd="$1" + shift + case "$cmd" in + "test"|"run"|"build") exec hare "$cmd" $NIX_HAREFLAGS "$@" ;; + *) exec hare ''${cmd:+"$cmd"} "$@" + esac + ''; + }; + hareWrapper = runCommand "hare-wrapper" { nativeBuildInputs = [ makeWrapper ]; } '' + mkdir -p $out/bin + install ${lib.getExe hareWrappedScript} $out/bin/hare + makeWrapper ${lib.getExe hare} $out/bin/hare-native \ + --inherit-argv0 \ + --unset AR \ + --unset LD \ + --unset CC + ''; +in +makeSetupHook { + name = "hare-hook"; + # The propagation of `qbe` and `harec` (harePropagationInputs) is needed for + # build frameworks like `haredo`, which set the HAREC and QBE env vars to + # `harec` and `qbe` respectively. We use the derivations from the `hare` + # package to assure that there's no different behavior between the `hareHook` + # and `hare` packages. + propagatedBuildInputs = [ hareWrapper ] ++ harePropagationInputs; + substitutions = { + hare_unconditional_flags = "-q -a${arch}"; + hare_stdlib = "${hare}/src/hare/stdlib"; + }; + meta = { + description = "A setup hook for the Hare compiler"; + inherit (hare.meta) badPlatforms platforms; + }; +} ./setup-hook.sh diff --git a/pkgs/by-name/ha/hare/package.nix b/pkgs/by-name/ha/hare/package.nix index faa766c056df..80c30e89a2b6 100644 --- a/pkgs/by-name/ha/hare/package.nix +++ b/pkgs/by-name/ha/hare/package.nix @@ -130,13 +130,6 @@ stdenv.mkDerivation (finalAttrs: { scdoc ]; - # Needed for build frameworks like `haredo`, which set the HAREC and QBE env vars to `harec` and - # `qbe` respectively. - propagatedBuildInputs = [ - harec - qbe - ]; - buildInputs = [ harec qbe @@ -171,8 +164,6 @@ stdenv.mkDerivation (finalAttrs: { ln -s configs/${platform}.mk config.mk ''; - setupHook = ./setup-hook.sh; - passthru = { updateScript = gitUpdater { }; tests = @@ -182,6 +173,8 @@ stdenv.mkDerivation (finalAttrs: { // lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) { mimeModule = callPackage ./mime-module-test.nix { hare = finalAttrs.finalPackage; }; }; + # To be propagated by `hareHook`. + inherit harec qbe; }; meta = { diff --git a/pkgs/by-name/ha/hare/setup-hook.sh b/pkgs/by-name/ha/hare/setup-hook.sh index d2d2c34354d6..3a427fd70328 100644 --- a/pkgs/by-name/ha/hare/setup-hook.sh +++ b/pkgs/by-name/ha/hare/setup-hook.sh @@ -1,9 +1,36 @@ -addHarepath () { - for haredir in third-party stdlib; do - if [[ -d "$1/src/hare/$haredir" ]]; then - addToSearchPath HAREPATH "$1/src/hare/$haredir" - fi - done +# shellcheck disable=SC2154,SC2034,SC2016 + +addHarepath() { + local -r thirdparty="${1-}/src/hare/third-party" + if [[ -d "$thirdparty" ]]; then + addToSearchPath HAREPATH "$thirdparty" + fi } +# Hare's stdlib should come after its third party libs, since the latter may +# expand or shadow the former. +readonly hareSetStdlibPhase=' +addToSearchPath HAREPATH "@hare_stdlib@" +' +readonly hareInfoPhase=' +echoCmd "HARECACHE" "$HARECACHE" +echoCmd "HAREPATH" "$HAREPATH" +echoCmd "hare" "$(command -v hare)" +echoCmd "hare-native" "$(command -v hare-native)" +' +prePhases+=("hareSetStdlibPhase" "hareInfoPhase") + +readonly hare_unconditional_flags="@hare_unconditional_flags@" +case "${hareBuildType:-"release"}" in +"release") export NIX_HAREFLAGS="-R $hare_unconditional_flags" ;; +"debug") export NIX_HAREFLAGS="$hare_unconditional_flags" ;; +*) + printf -- 'Invalid hareBuildType: "%s"\n' "${hareBuildType-}" + exit 1 + ;; +esac + +HARECACHE="$(mktemp -d)" +export HARECACHE + addEnvHooks "$hostOffset" addHarepath diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2c8cad1325ba..2e7ff897c020 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -25196,6 +25196,10 @@ with pkgs; leaps = callPackage ../development/tools/leaps { }; + ### DEVELOPMENT / HARE + + hareHook = callPackage ../by-name/ha/hare/hook.nix { }; + ### DEVELOPMENT / JAVA MODULES javaPackages = recurseIntoAttrs (callPackage ./java-packages.nix { });