Skip to content

Conversation

SpotlightKid
Copy link
Contributor

@SpotlightKid SpotlightKid commented Sep 22, 2024

ref https://forum.nim-lang.org/t/12524

Potential fix for #13 on POSIX and Windows systems.

On non-posix/windows systems still uses the old behaviour using startProcess. Use --undef:useExec to switch back to old behaviour on posix too.

@PMunch
Copy link
Collaborator

PMunch commented Sep 24, 2024

Great work! You do mention however on the forum that some manual steps are required to replace the proxy executables. Maybe it would be better to add something in updateSelf so that a simple choosenim update self would also rebuild these? Not sure why that's not already done, the way it is now the choosenim version only pertains to the actual choosenim binary and the proxy exes are just whichever version you happened to start your choosenim install on.

@SpotlightKid
Copy link
Contributor Author

Maybe it would be better to add something in updateSelf so that a simple choosenim update self would also rebuild these?

The proxyexe binary is built into the choosenim executable. It gets written to ~/.nimble/bin/{nim,...}, when choosenim switches to a different Nim channel/version.

So actually, contrary to what I wrote on the forum, currently it isn't necessary to remove the old proxyexe binaries, just to switch to a new (or the same) version of Nim with choosenim after updating choosenim. See the code here:

let proxiesInstalled = params.areProxiesInstalled(proxiesToInstall)

(areProxiesInstalled also checks whether the proxyexe file is up-to-date.)

Updating the proxyexe binaries when choosenim updates itself, can be easily done (see below), but belongs in a different PR, imho, and also doesn't help when somebody just updates choosenim using nimble install choosenim or via a Linux distro package.

diff --git a/src/choosenim.nim b/src/choosenim.nim
index 3306e01..c1b628a 100644
--- a/src/choosenim.nim
+++ b/src/choosenim.nim
@@ -167,6 +167,27 @@ proc updateSelf(params: CliParams) =
   display("Info:", "Updated choosenim to version " & $version,
           Success, HighPriority)
 
+  # Any Nim installation currently activated by choosenim?
+  if $getCurrentVersion(params) != "":
+    var proxiesToInstall = @proxies
+
+    # Handle MingW proxies.
+    when defined(windows):
+      if not isDefaultCCInPath(params):
+        let mingwBin = getMingwBin(params)
+        if not fileExists(mingwBin / "gcc".addFileExt(ExeExt)):
+          let msg = "No 'gcc' binary found in '$1'." % mingwBin
+          raise newException(ChooseNimError, msg)
+
+        proxiesToInstall.add(mingwProxies)
+
+    if not params.areProxiesInstalled(proxiesToInstall):
+      # Create the proxy executables.
+      for proxy in proxiesToInstall:
+        writeProxy(proxy, params)
+
+
+
 proc update(params: CliParams) =
   if params.commands.len != 2:
     raise newException(ChooseNimError,
diff --git a/src/choosenimpkg/switcher.nim b/src/choosenimpkg/switcher.nim
index 2965859..c195e13 100644
--- a/src/choosenimpkg/switcher.nim
+++ b/src/choosenimpkg/switcher.nim
@@ -107,7 +107,7 @@ proc getSelectedPath*(params: CliParams): string =
 proc getProxyPath(params: CliParams, bin: string): string =
   return params.getBinDir() / bin.addFileExt(ExeExt)
 
-proc areProxiesInstalled(params: CliParams, proxies: openarray[string]): bool =
+proc areProxiesInstalled*(params: CliParams, proxies: openarray[string]): bool =
   result = true
   let proxyExe = proxyToUse()
   for proxy in proxies:
@@ -173,7 +173,7 @@ proc getNimbleVersion(toolchainPath: string): Version =
     display("Warning:", "Could not find toolchain's Nimble version.",
             Warning, MediumPriority)
 
-proc writeProxy(bin: string, params: CliParams) =
+proc writeProxy*(bin: string, params: CliParams) =
   # Create the ~/.nimble/bin dir in case it doesn't exist.
   createDir(params.getBinDir())
 

@SpotlightKid SpotlightKid force-pushed the fix/proxyexe-use-execv branch 2 times, most recently from c49fef9 to 5c9cb7e Compare September 26, 2024 00:43
@SpotlightKid SpotlightKid changed the title fix: use execv in proxyexe on posix fix: use execv in proxyexe Sep 26, 2024
@SpotlightKid
Copy link
Contributor Author

Now that there is an implementation of this PR for Windows as well, I will try to add sensible tests. Not sure how yet, but I will come up with something.

@RokkuCode
Copy link

Hi there, thanks for your work. I wanted to test your implementation, but i have seen, that your fork does not implement the newest additions. could you update your branch to the latest commits, so i can try it out? i would appreciate it.

@SpotlightKid SpotlightKid force-pushed the fix/proxyexe-use-execv branch 2 times, most recently from c8c45e9 to a65877e Compare March 25, 2025 03:42
@SpotlightKid
Copy link
Contributor Author

SpotlightKid commented Mar 25, 2025

could you update your branch to the latest commits, so i can try it out?

I've rebased the PR branch on master.

Ignore all the commits listed above. I'm not sure what I did there but I hope everything is in order again now.

@SpotlightKid SpotlightKid force-pushed the fix/proxyexe-use-execv branch from a65877e to c032684 Compare March 25, 2025 15:25
@SpotlightKid
Copy link
Contributor Author

I never seem to get around to writing proper tests for it. In fact, I don't really know how to best write these test and I could use some help!

I've bee using this patch in the AUR package of choosenim for months now and it works perfectly for me and I haven't got any reports of problems with it from other AUR user either.

@SpotlightKid SpotlightKid marked this pull request as ready for review April 17, 2025 15:09
@Araq
Copy link
Member

Araq commented Apr 20, 2025

@SpotlightKid yet the CI is red, what's up with that?

@SpotlightKid
Copy link
Contributor Author

SpotlightKid commented Apr 20, 2025

@Araq The CI uses an outdated runner. Support for ubuntu-20.04 has been removed from Github Actions recently.

I'll have a look what's up with the other OSes.

@SpotlightKid SpotlightKid force-pushed the fix/proxyexe-use-execv branch from 72c278f to 954da31 Compare April 20, 2025 17:15
@ringabout
Copy link
Member

CI failure is not caused by this PR, we need to wait for nightlies fixing

@ringabout ringabout closed this Apr 22, 2025
@ringabout ringabout reopened this Apr 22, 2025
@RokkuCode
Copy link

a little feedback: i am using your patches since march and hadn't any problems with them. yes, there are missing test, but the current situation for linux users is bad, especially for newcomers, because they hit multiple walls until to find the right issues and fix it by hand. so i would vote for applying the patches, to get a step forward. better as staying in the current situation.

@Araq Araq merged commit 98ae2a8 into nim-lang:master May 11, 2025
10 of 16 checks passed
@SpotlightKid SpotlightKid deleted the fix/proxyexe-use-execv branch July 7, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants