From 22fc4d40b50756cff043e5c591b5243b693535c4 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 8 Oct 2024 15:18:16 +0300 Subject: [PATCH 1/7] test bundling nif --- compiler/nim.cfg | 4 ++++ compiler/nim.nim | 2 ++ koch.nim | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/compiler/nim.cfg b/compiler/nim.cfg index 87c35a7110845..d9936284e6765 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -2,6 +2,10 @@ hint[XDeclaredButNotUsed]:off +# config needed for nif to import the compiler: +define:nifCompilerInPath +path:".." + define:booting define:nimcore define:nimPreviewSlimSystem diff --git a/compiler/nim.nim b/compiler/nim.nim index 005f11a580e7f..dbb9cfc4d148f 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -28,6 +28,8 @@ import commands, options, msgs, extccomp, main, idents, lineinfos, cmdlinehelper, pathutils, modulegraphs +import ../dist/nif/src/[nifler/nifler, xelim/xelim, nifgram/nifgram, gear2/gear2] + from std/browsers import openDefaultBrowser from nodejs import findNodeJs diff --git a/koch.nim b/koch.nim index 77bc2299f3325..99e397c17b485 100644 --- a/koch.nim +++ b/koch.nim @@ -15,6 +15,7 @@ const AtlasStableCommit = "5faec3e9a33afe99a7d22377dd1b45a5391f5504" ChecksumsStableCommit = "bd9bf4eaea124bf8d01e08f92ac1b14c6879d8d3" SatStableCommit = "faf1617f44d7632ee9601ebc13887644925dcc01" + NifStableCommit = "HEAD" # examples of possible values for fusion: #head, #ea82b54, 1.2.3 FusionStableHash = "#372ee4313827ef9f2ea388840f7d6b46c2b1b014" @@ -78,6 +79,7 @@ Possible Commands: nimble builds the Nimble tool atlas builds the Atlas tool checksums installs the checksums dependency + nif installs the nif dependency fusion installs fusion via Nimble Boot options: @@ -210,7 +212,15 @@ proc bundleChecksums(latest: bool) = let commit = if latest: "HEAD" else: ChecksumsStableCommit cloneDependency(distDir, "https://github.com/nim-lang/checksums.git", commit, allowBundled = true) +proc bundleNif(latest: bool) = + when false: + let commit = if latest: "HEAD" else: NifStableCommit + cloneDependency(distDir, "https://github.com/nim-lang/nif.git", commit, allowBundled = true) + else: + cloneDependency(distDir, "https://github.com/metagn/nif.git", "slimsystem", allowBundled = true) + proc zip(latest: bool; args: string) = + bundleNif(latest) bundleChecksums(latest) bundleNimbleExe(latest, args) bundleAtlasExe(latest, args) @@ -265,6 +275,7 @@ proc testTools(args: string = "") = nimCompileFold("Compile testament", "testament/testament.nim", options = "-d:release " & args) proc nsis(latest: bool; args: string) = + bundleNif(latest) bundleChecksums(latest) bundleNimbleExe(latest, args) bundleAtlasExe(latest, args) @@ -345,6 +356,7 @@ proc boot(args: string, skipIntegrityCheck: bool) = let smartNimcache = (if "release" in args or "danger" in args: "nimcache/r_" else: "nimcache/d_") & hostOS & "_" & hostCPU + bundleNif(false) bundleChecksums(false) let usingLibFFI = "nimHasLibFFI" in args @@ -508,6 +520,7 @@ proc temp(args: string) = result[1].add " " & quoteShell(args[i]) inc i + bundleNif(false) bundleChecksums(false) let d = getAppDir() @@ -764,6 +777,8 @@ when isMainModule: bundleAtlasExe(latest, op.cmdLineRest) of "checksums": bundleChecksums(latest) + of "nif": + bundleNif(latest) of "pushcsource": quit "use this instead: https://github.com/nim-lang/csources_v1/blob/master/push_c_code.nim" of "valgrind": valgrind(op.cmdLineRest) From 0d62be8f209712f448a86d8beafd9a6c0bf973a3 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 8 Oct 2024 15:26:30 +0300 Subject: [PATCH 2/7] shim ensureMove --- lib/system.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/system.nim b/lib/system.nim index 2f9cdc5f91334..4f355d1c24e17 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -164,6 +164,9 @@ when defined(nimHasEnsureMove): doAssert y == "Hello" foo() discard "implemented in injectdestructors" +else: + template ensureMove*[T](x: T): T = + x type range*[T]{.magic: "Range".} ## Generic type to construct range types. From b064d7985f0b40b1f5f8bc872f0b5bfafbbb926a Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 8 Oct 2024 15:43:18 +0300 Subject: [PATCH 3/7] worked around csources bug in nif From 698804d860fece41b9f6c60752a0eeafd024c322 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 8 Oct 2024 15:54:41 +0300 Subject: [PATCH 4/7] worked around again From 81a1b18f79e36f38c4cdab484df123aed78af89e Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 8 Oct 2024 16:06:09 +0300 Subject: [PATCH 5/7] again From 2df357944ea7e93feb9e08daf14ef179df618775 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 8 Oct 2024 17:37:57 +0300 Subject: [PATCH 6/7] use master, should be final test --- koch.nim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/koch.nim b/koch.nim index 99e397c17b485..9252bbc75642b 100644 --- a/koch.nim +++ b/koch.nim @@ -15,7 +15,7 @@ const AtlasStableCommit = "5faec3e9a33afe99a7d22377dd1b45a5391f5504" ChecksumsStableCommit = "bd9bf4eaea124bf8d01e08f92ac1b14c6879d8d3" SatStableCommit = "faf1617f44d7632ee9601ebc13887644925dcc01" - NifStableCommit = "HEAD" + NifStableCommit = "5a1570de3d9c0f246ba903c6780e5c0ecb6ddbfc" # examples of possible values for fusion: #head, #ea82b54, 1.2.3 FusionStableHash = "#372ee4313827ef9f2ea388840f7d6b46c2b1b014" @@ -213,11 +213,8 @@ proc bundleChecksums(latest: bool) = cloneDependency(distDir, "https://github.com/nim-lang/checksums.git", commit, allowBundled = true) proc bundleNif(latest: bool) = - when false: - let commit = if latest: "HEAD" else: NifStableCommit - cloneDependency(distDir, "https://github.com/nim-lang/nif.git", commit, allowBundled = true) - else: - cloneDependency(distDir, "https://github.com/metagn/nif.git", "slimsystem", allowBundled = true) + let commit = if latest: "HEAD" else: NifStableCommit + cloneDependency(distDir, "https://github.com/nim-lang/nif.git", commit, allowBundled = true) proc zip(latest: bool; args: string) = bundleNif(latest) From 980c01fe823ad7a3f2110729598768c993df8f42 Mon Sep 17 00:00:00 2001 From: metagn Date: Wed, 9 Oct 2024 18:43:58 +0300 Subject: [PATCH 7/7] finish up --- compiler/nim.cfg | 5 +++-- compiler/nim.nim | 4 +++- koch.nim | 3 ++- lib/system.nim | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/nim.cfg b/compiler/nim.cfg index d9936284e6765..531e5bf6e1f33 100644 --- a/compiler/nim.cfg +++ b/compiler/nim.cfg @@ -2,9 +2,10 @@ hint[XDeclaredButNotUsed]:off -# config needed for nif to import the compiler: -define:nifCompilerInPath +# allow dependencies to import the compiler via `import compiler / ...`: path:".." +# nif uses `--path:$nim` by default, make it use the current compiler instead: +define:nifCompilerInPath define:booting define:nimcore diff --git a/compiler/nim.nim b/compiler/nim.nim index dbb9cfc4d148f..4be4e91d6a2b6 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -28,7 +28,9 @@ import commands, options, msgs, extccomp, main, idents, lineinfos, cmdlinehelper, pathutils, modulegraphs -import ../dist/nif/src/[nifler/nifler, xelim/xelim, nifgram/nifgram, gear2/gear2] +when defined(testNifImports): + # temporary until nif is actually used in the compiler + import ../dist/nif/src/[nifler/nifler, xelim/xelim, nifgram/nifgram, gear2/gear2] from std/browsers import openDefaultBrowser from nodejs import findNodeJs diff --git a/koch.nim b/koch.nim index 9252bbc75642b..b7555089c5ff6 100644 --- a/koch.nim +++ b/koch.nim @@ -596,7 +596,8 @@ proc runCI(cmd: string) = # boot without -d:nimHasLibFFI to make sure this still works # `--lib:lib` is needed for bootstrap on openbsd, for reasons described in # https://github.com/nim-lang/Nim/pull/14291 (`getAppFilename` bugsfor older nim on openbsd). - kochExecFold("Boot Nim ORC", "boot -d:release -d:nimStrictMode --lib:lib") + kochExecFold("Boot Nim ORC", "boot -d:release -d:nimStrictMode --lib:lib -d:testNifImports") + # remove -d:testNifImports when nif is actually used when false: # debugging: when you need to run only 1 test in CI, use something like this: execFold("debugging test", "nim r tests/stdlib/tosproc.nim") diff --git a/lib/system.nim b/lib/system.nim index 4f355d1c24e17..b202f0db3e73d 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -166,6 +166,7 @@ when defined(nimHasEnsureMove): discard "implemented in injectdestructors" else: template ensureMove*[T](x: T): T = + # no-op for bootstrapping x type