Troubles building "nimble" with nim

2022-07-06 Thread Trev

Hello Guix!

I am in the weeds while trying to properly build "nimble", the package
manager that is included with the nim programming language. The current
guix package (gnu/packages/nim) completely misses this build step. I
wonder if previous contributors also struggled with this.

For some context I am attempting to directly replicate these steps from
https://nim-lang.org/install_unix.html:

#+BEGIN_QUOTE
sh build.sh
bin/nim c koch
./koch boot -d:release
./koch tools
#+END_QUOTE

My (and the current package record) can build the nim binary using gcc, no 
problem. However when we get to the part where nim builds its own features with 
the compiled compiler, something seems to be trying to call =/bin/sh= directly, 
despite hard-coded references to that process having been been substituted out.

I have submitted a ticket with Nim here just so that I may ask some thoughtful 
questions. That conversation is here: 
https://github.com/nim-lang/Nim/issues/19976

The error output is:

#+BEGIN_SRC sh
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
#+END_SRC

My current attempt at packaging this looks like this:

#+BEGIN_SRC scheme
(define-module (gnu packages nim)
  #:use-module (guix build-system gnu)
  #:use-module (guix gexp)
  #:use-module (guix download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages pcre)
  #:use-module (gnu packages tls)
  #:use-module (gnu packages cmake))

(define-public nim
  (package
(name "nim")
(version "1.6.6")
(source
 (origin
   (method url-fetch)
   (uri (string-append "https://nim-lang.org/download/";
   name "-" version ".tar.xz"))
   (sha256
(base32 "0lm4450ig8k4l3rzxv6kcqji5l1lzicsw76ckwxm0q9qdz713cb7"
(build-system gnu-build-system)
(native-inputs (list pcre openssl cmake))
(arguments
 `(#:tests? #f ; No tests.
   #:phases
   (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"
 (("/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))
   (substitute* (find-files "c_code" "stdlib_osproc.c")
 (("\"/bin/sh\", 7") (format #f "~s, ~s" sh (string-length 
sh)
 #t))
 (replace 'build
   (lambda _
 (setenv "XDG_CACHE_HOME" "./cache-home")
 (mkdir-p "./cache-home")
 (invoke "sh" "build.sh")
 (invoke "./bin/nim" "c" "koch")
 (invoke "koch" "boot" "-d:release")
 (invoke "koch" "tools")
 #t))
 (replace 'install
   (lambda* (#:key outputs #:allow-other-keys)
 (let ((out (assoc-ref outputs "out")))
   (mkdir-p (string-append out "/usr/bin"))
   (invoke "./install.sh" (string-append out "/usr/bin"))
   #t))
(home-page "https://nim-lang.org";)
(synopsis "Statically-typed, imperative programming language")
(description "Nim (formerly known as Nimrod) is a statically-typed,
imperative programming language that tries to give the programmer ultimate power
without compromises on runtime efficiency.  This means it focuses on 
compile-time
mechanisms in all their various forms.")
(license license:expat)))
#+END_SRC

I have tried:

1. Symlinking (without any success) /bin/sh to (which "bash")
2. Exporting $SHELL to (which "bash")
3. Attempted (without much luck) to ~alias cc=gcc~ to see if it's not the shell 
that's missing, it's the command "cc", and adding cmake as a 

Re: Set up cgit with git-http-backend properly

2022-07-06 Thread pelzflorian (Florian Pelz)
Hello Simon.

Simon Streit  writes:
> After
> modifying
>
> (string-append "~ /" (string-trim-both uri-path #\/) "(/.*)")
>
> to
>
> (string-append "~ " (string-trim-both uri-path #\/) "(/.*)")
>
> serving and cloning from https://git.example.com/repo(.git) works now.
> But it doesn't when cgit is enabled and serving repositories in the same
> path at the same time.

Glad you have a working setup.  Though this sounds like even cgit cannot
be served from / even if the Guix service definition were fixed.  But
 looks like a configuration
that seems to use /, though instead of "~ /" they special-case the paths
under /.

Regards,
Florian



Android.mk build system limitations

2022-07-06 Thread Denis 'GNUtoo' Carikli
Hi,

I'm maintaining a library that can be used in both Android and
GNU/Linux. To do quick build tests in various configurations before
pushing commits, I use a guix.scm[1] file.

With that I'm also testing the build with the Android.mk to find
potential issues.

There are several limitations with the Android.mk build system in Guix.
A well known one is the inability to handle cross compilation, so
people using that build system typically work around that with
something like that[2]:
>(modify-phases %standard-phases
>  (add-before 'build 'patch-host
>(lambda _
>  ;; TODO: Cross-compile.
>  (substitute* "Android.mk"
>   (("BUILD_STATIC_LIBRARY") "BUILD_HOST_STATIC_LIBRARY"))
>  #t)))

However I found an issue that is more problematic: this build system
expects an Android.mk with a single target (which is defined
with "LOCAL_MODULE :=" in the Android.mk). 

Until now I didn't implement that in my guix.scm and only built the
library and not the associated utilities.

But then recently I found that the build broke in Android because I
forgot to add some source code files for one of the utilities in the
Android.mk file, so I now really want to build the utilities too in
that guix.scm with the Android.mk build system.

With some help on #guix on liberachat, I managed to run the make
multiple times, and to pass it a list of local-modules to build.

The new build function looks like that[3]:
> (replace 'build
>  (lambda*
>   (#:key inputs make-flags native-inputs outputs #:allow-other-keys)
>(for-each
> (lambda (arg)
>  (substitute* "Android.mk"
>   (("BUILD_EXECUTABLE")
> "BUILD_HOST_EXECUTABLE"))
>   ((assoc-ref %standard-phases 'build)
>#:make-flags (append make-flags
>  (list (string-append "LOCAL_MODULE=" arg)
>  ,local-modules)
>   #t))

And the new installation function looks really similar:
> (replace 'install
>  (lambda*
>   (#:key inputs make-flags native-inputs outputs #:allow-other-keys)
>  (for-each
>(lambda (arg)
>  ((assoc-ref %standard-phases 'install)
>   #:inputs inputs
>   #:outputs outputs
>   #:make-flags
>   (append make-flags
>   (list (string-append "LOCAL_MODULE=" arg)
>,local-modules)
>   #t))

But it then ends up building the first local-module in the local-modules
list, many times, and install it with different names.

After building, we can see that https-send-sms was built correctly:
> $ 
> /gnu/store/[...]-libsamsung-ipc-gcc-android-0.0-HEAD.c4d664a/bin/https-send-sms
>  
> Usage:
> /gnu/store/[...]-libsamsung-ipc-gcc-android-0.0-HEAD.c4d664a/bin/https-send-sms
> free-mobile   
> 
> Example:
>   
> /gnu/store/[...]-libsamsung-ipc-gcc-android-0.0-HEAD.c4d664a/bin/https-send-sms
> free-mobile "12345678" "1234abcdEFGH" "hello world!"
> $ /gnu/store/[...]-libsamsung-ipc-gcc-android-0.0-HEAD.c4d664a/bin/ipc-test

But the same source code was also used to build ipc-test
> Usage: 
> /gnu/store/[...]-libsamsung-ipc-gcc-android-0.0-HEAD.c4d664a/bin/ipc-test 
> free-mobile   
> 
> Example:
>   
> /gnu/store/[...]-libsamsung-ipc-gcc-android-0.0-HEAD.c4d664a/bin/ipc-test 
> free-mobile "12345678" "1234abcdEFGH" "hello world!"

And if ipc-test source code was used we would end up with something
like that instead:
> $ ipc-test
> Creating client failed

So I'm a bit confused on how to solve this issue. I'm also not sure if
it needs to be solved in Guix or in the underlying Makefiles that
makes it possible to use Android.mk files under GNU/Linux.

I'm writing that mail in the hope that people who knows better the
implementation of the Android.mk build system in Guix would have
pointers to help me solve that issue.

References:
---
[1]https://git.replicant.us/replicant/hardware_replicant_libsamsung-ipc/plain/scripts/guix.scm
[2]from android-safe-iop from gnu/packages/android.scm in Guix
[3]https://git.replicant.us/contrib/GNUtoo/replicant/hardware_replicant_libsamsung-ipc/plain/scripts/guix.scm?h=c4d664ae71eb65415d799ada8018cfa49f6fb7fb

Denis.


pgpj_PfBilXFe.pgp
Description: OpenPGP digital signature