nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.41k stars 1.47k forks source link

Building nimble for Guix: /bin/sh Could not find command #19976

Closed trev-dev closed 1 year ago

trev-dev commented 2 years ago

Hello There!

This is definitely an edge case, but I'm out of ideas and need to ask questions.

I am trying to build nim and nimble to Guix. The current package (and the one I am working on) currently can only seem to build the nim compiler.

Choosenim would be a nice option but it seems to fail at finding dependencies as well.

Like Nix, Guix builds packages in a contained environment. I have patched all of the shebangs, and swapped out hard-coded references to /bin/sh to the canonical path.

I have tried symlinking bash to /bin/sh in the build environment, which it simply will not let me do :)

I have tried exporting my $SHELL as the canonical path to /bin/sh. the end result is the same: we compile nim, then fail to compile koch with nim:

c_code/2_2/stdlib_browsers.nim.o c_code/2_2/@mnim.nim.o -ldl -lm -lrt
: SUCCESS
Hint: used config file '/tmp/guix-build-nim-1.6.6.drv-0/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/tmp/guix-build-nim-1.6.6.drv-0/nim-1.6.6/config/config.nims' [Conf]
......................................................................................................................
CC: stdlib_digitsutils.nim
Error: invocation of external compiler program failed. No such file or directory
Additional info: Could not find command: '/bin/sh'. OS error: No such file or directory 2
error: in phase 'build': uncaught exception:
%exception #<&invoke-error program: "./bin/nim" arguments: ("c" "koch") exit-status: 1 term-signal: #f stop-signal: #f> 
phase `build' failed after 96.6 seconds
command "./bin/nim" "c" "koch" failed with status 1

If it's at all meaningful to whomever may view this, I can show you what the build script is doing so far:

(modify-phases %standard-phases
  (delete 'configure) ; no configure script
  (add-after 'unpack 'patch-installer
    (lambda* (#:key outputs #:allow-other-keys)
      (let ((out (assoc-ref outputs "out")))
        (substitute* "install.sh" ; Patch install destinations
          (("/usr/") (string-append out "/usr/"))
          (("/etc/") (string-append out "/etc/"))
          (("/opt/") (string-append out "/opt/")))
        #t)))
  (add-after 'patch-source-shebangs 'patch-more-shebangs
    (lambda _
      (let ((sh (which "sh")))
        (substitute* '("tests/stdlib/tosprocterminate.nim"
                       "tests/stdlib/tstrscans.nim"
                       "lib/pure/osproc.nim")
          (("/bin/sh") sh)) ; patch static references to /bin/sh
        (substitute* (find-files "c_code" "stdlib_osproc.c")
          (("\"/bin/sh\", 7") (format #f "~s, ~s" sh (string-length sh)))))
      #t)) ; These don't show up in grep (anymore?) Maybe not necessary
  (replace 'build
    (lambda _
      ;; Fix the non-existant XDG cache problem
      (setenv "XDG_CACHE_HOME" "./cache-home")
      (mkdir-p "./cache-home")
      ;; Start building stuff
      (invoke "sh" "build.sh")
      (invoke "./bin/nim" "c" "koch") ; <-- we fail here
      (invoke "koch" "boot" "-d:release")
      (invoke "koch" "tools")
      #t))
  (replace 'install
    (lambda* (#:key outputs #:allow-other-keys)
      (let ((out (assoc-ref outputs "out")))
        ;; Hopefully install the things.
        (mkdir-p (string-append out "/usr/bin"))
        (invoke "./install.sh" (string-append out "/usr/bin"))
        #t))))

Could anyone shed some light on which aspect of bin/nim c koch is trying to call /bin/sh directly?

Araq commented 2 years ago

Look into osproc and poUseShell, it's likely that koch.nim ends up using this somehow.

trev-dev commented 2 years ago

I can't seem to grep poUseShell, but there seems to be many process related functions in osproc. My script already patches hard coded instances in osproc, let's see what I can find.

trev-dev commented 1 year ago

Looks like upstream has moved on without me! Closing.