nim-2_2: move to pkgs/by-name from nim2

This commit is contained in:
Emery Hemingway 2024-10-27 18:41:20 +00:00
parent 90f24ad023
commit 1e1bc01db7
6 changed files with 161 additions and 80 deletions

View File

@ -0,0 +1,156 @@
# When updating this package please check that all other versions of Nim
# evaluate because they reuse definitions from the latest compiler.
{
lib,
stdenv,
buildPackages,
darwin,
makeWrapper,
openssl,
pcre,
nim-unwrapped-2_2 ? buildPackages.nim-unwrapped-2_2,
Security ? darwin.Security,
}:
let
wrapNim =
{ nimUnwrapped, patches }:
let
targetPlatformConfig = stdenv.targetPlatform.config;
in
stdenv.mkDerivation (finalAttrs: {
name = "${targetPlatformConfig}-nim-wrapper-${nimUnwrapped.version}";
inherit (nimUnwrapped) version;
preferLocalBuild = true;
strictDeps = true;
nativeBuildInputs = [ makeWrapper ];
# Needed for any nim package that uses the standard library's
# 'std/sysrand' module.
depsTargetTargetPropagated = lib.optional stdenv.hostPlatform.isDarwin Security;
inherit patches;
unpackPhase = ''
runHook preUnpack
tar xf ${nimUnwrapped.src} nim-$version/config
cd nim-$version
runHook postUnpack
'';
dontConfigure = true;
buildPhase =
# Configure the Nim compiler to use $CC and $CXX as backends
# The compiler is configured by two configuration files, each with
# a different DSL. The order of evaluation matters and that order
# is not documented, so duplicate the configuration across both files.
''
runHook preBuild
cat >> config/config.nims << WTF
switch("os", "${nimUnwrapped.passthru.nimTarget.os}")
switch("cpu", "${nimUnwrapped.passthru.nimTarget.cpu}")
switch("define", "nixbuild")
# Configure the compiler using the $CC set by Nix at build time
import strutils
let cc = getEnv"CC"
if cc.contains("gcc"):
switch("cc", "gcc")
elif cc.contains("clang"):
switch("cc", "clang")
WTF
mv config/nim.cfg config/nim.cfg.old
cat > config/nim.cfg << WTF
os = "${nimUnwrapped.passthru.nimTarget.os}"
cpu = "${nimUnwrapped.passthru.nimTarget.cpu}"
define:"nixbuild"
WTF
cat >> config/nim.cfg < config/nim.cfg.old
rm config/nim.cfg.old
cat >> config/nim.cfg << WTF
clang.cpp.exe %= "\$CXX"
clang.cpp.linkerexe %= "\$CXX"
clang.exe %= "\$CC"
clang.linkerexe %= "\$CC"
gcc.cpp.exe %= "\$CXX"
gcc.cpp.linkerexe %= "\$CXX"
gcc.exe %= "\$CC"
gcc.linkerexe %= "\$CC"
WTF
runHook postBuild
'';
wrapperArgs = lib.optionals (!(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) [
"--prefix PATH : ${lib.makeBinPath [ buildPackages.gdb ]}:${placeholder "out"}/bin"
# Used by nim-gdb
"--prefix LD_LIBRARY_PATH : ${
lib.makeLibraryPath [
openssl
pcre
]
}"
# These libraries may be referred to by the standard library.
# This is broken for cross-compilation because the package
# set will be shifted back by nativeBuildInputs.
"--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim"
# Use the custom configuration
];
installPhase =
''
runHook preInstall
mkdir -p $out/bin $out/etc
cp -r config $out/etc/nim
for binpath in ${nimUnwrapped}/bin/nim?*; do
local binname=`basename $binpath`
makeWrapper \
$binpath $out/bin/${targetPlatformConfig}-$binname \
$wrapperArgs
ln -s $out/bin/${targetPlatformConfig}-$binname $out/bin/$binname
done
makeWrapper \
${nimUnwrapped}/nim/bin/nim $out/bin/${targetPlatformConfig}-nim \
--set-default CC $(command -v $CC) \
--set-default CXX $(command -v $CXX) \
$wrapperArgs
ln -s $out/bin/${targetPlatformConfig}-nim $out/bin/nim
makeWrapper \
${nimUnwrapped}/bin/testament $out/bin/${targetPlatformConfig}-testament \
$wrapperArgs
ln -s $out/bin/${targetPlatformConfig}-testament $out/bin/testament
''
+ ''
runHook postInstall
'';
passthru = nimUnwrapped.passthru // {
inherit wrapNim;
nim = nimUnwrapped;
};
meta = nimUnwrapped.meta // {
description = nimUnwrapped.meta.description + " (${targetPlatformConfig} wrapper)";
platforms = with lib.platforms; unix ++ genode ++ windows;
};
});
in
wrapNim {
nimUnwrapped = nim-unwrapped-2_2;
patches = [ ./nim2.cfg.patch ];
}

View File

@ -3,7 +3,7 @@
{ lib, callPackage, buildPackages, stdenv, fetchurl, fetchgit { lib, callPackage, buildPackages, stdenv, fetchurl, fetchgit
, makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security , makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security
, nim-unwrapped-2, nim-unwrapped-1, nim }: , nim-unwrapped-2, nim-unwrapped-1 }:
let let
inherit (nim-unwrapped-2.passthru) nimHost nimTarget; inherit (nim-unwrapped-2.passthru) nimHost nimTarget;
@ -157,11 +157,6 @@ in {
}); });
in { in {
nim2 = wrapNim {
nim' = buildPackages.nim-unwrapped-2_2;
patches = [ ./nim2.cfg.patch ];
};
nim1 = wrapNim { nim1 = wrapNim {
nim' = buildPackages.nim-unwrapped-1; nim' = buildPackages.nim-unwrapped-1;
patches = [ ./nim.cfg.patch ]; patches = [ ./nim.cfg.patch ];

View File

@ -1,48 +0,0 @@
diff --git a/compiler/modulepaths.nim b/compiler/modulepaths.nim
index c9e6060e5..acb289498 100644
--- a/compiler/modulepaths.nim
+++ b/compiler/modulepaths.nim
@@ -79,6 +79,13 @@ proc checkModuleName*(conf: ConfigRef; n: PNode; doLocalError=true): FileIndex =
else:
result = fileInfoIdx(conf, fullPath)
+proc rot13(result: var string) =
+ for i, c in result:
+ case c
+ of 'a'..'m', 'A'..'M': result[i] = char(c.uint8 + 13)
+ of 'n'..'z', 'N'..'Z': result[i] = char(c.uint8 - 13)
+ else: discard
+
proc mangleModuleName*(conf: ConfigRef; path: AbsoluteFile): string =
## Mangle a relative module path to avoid path and symbol collisions.
##
@@ -87,9 +94,11 @@ proc mangleModuleName*(conf: ConfigRef; path: AbsoluteFile): string =
##
## Example:
## `foo-#head/../bar` becomes `@foo-@hhead@s..@sbar`
- "@m" & relativeTo(path, conf.projectPath).string.multiReplace(
+ result = "@m" & relativeTo(path, conf.projectPath).string.multiReplace(
{$os.DirSep: "@s", $os.AltSep: "@s", "#": "@h", "@": "@@", ":": "@c"})
+ rot13(result)
proc demangleModuleName*(path: string): string =
## Demangle a relative module path.
result = path.multiReplace({"@@": "@", "@h": "#", "@s": "/", "@m": "", "@c": ":"})
+ rot13(result)
diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim
index 77762d23a..59dd8903a 100644
--- a/compiler/modulegraphs.nim
+++ b/compiler/modulegraphs.nim
@@ -503,7 +503,11 @@ proc uniqueModuleName*(conf: ConfigRef; m: PSym): string =
for i in 0..<trunc:
let c = rel[i]
case c
- of 'a'..'z', '0'..'9':
+ of 'a'..'m':
+ result.add char(c.uint8 + 13)
+ of 'n'..'z':
+ result.add char(c.uint8 - 13)
+ of '0'..'9':
result.add c
of {os.DirSep, os.AltSep}:
result.add 'Z' # because it looks a bit like '/'

View File

@ -1,25 +0,0 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash nix-update curl coreutils jq
set -ex
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
curl_github() {
curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} "$@"
}
case "$UPDATE_NIX_ATTR_PATH" in
nim)
latestTag=$(curl_github https://api.github.com/repos/nim-lang/Nim/releases/latest | jq -r ".tag_name")
latestVersion="$(expr "$latestTag" : 'v\(.*\)')"
echo "Updating Nim"
nix-update --version "$latestVersion" \
--override-filename "$SCRIPT_DIR/default.nix" \
nim
*)
echo "Unknown attr path $UPDATE_NIX_ATTR_PATH"
;;
esac

View File

@ -15325,10 +15325,13 @@ with pkgs;
inherit (callPackages ../development/compilers/nim inherit (callPackages ../development/compilers/nim
{ inherit (darwin) Security; } { inherit (darwin) Security; }
) nim-unwrapped-1 nim1 nim2; ) nim1;
nim = nim2; nim = nim2;
nim2 = nim-2_2;
nim-unwrapped = nim-unwrapped-2_2; nim-unwrapped = nim-unwrapped-2_2;
nim-unwrapped-2 = nim-unwrapped-2_2; nim-unwrapped-2 = nim-unwrapped-2_2;
buildNimPackage = callPackage ../development/compilers/nim/build-nim-package.nix { }; buildNimPackage = callPackage ../development/compilers/nim/build-nim-package.nix { };
nimOverrides = callPackage ./nim-overrides.nix { }; nimOverrides = callPackage ./nim-overrides.nix { };