From 81e08167e2f61ca23a714f2d040589bfbd1d7676 Mon Sep 17 00:00:00 2001 From: Buldram Date: Wed, 19 Feb 2025 23:16:12 -0500 Subject: [PATCH] nim: fix Musl build with new compilers (#48487) * nim: fix build with new compilers * narrow condition for disabling warnings * move flags into offending module disables warnings also for compiling projects other than the Nim compiler when necessary * specify different versions pthread modules * instead patch SysThread type * adapt patch for old Nim versions * Specify hypothetical `:@0.19.6` for patch version constraint --- .../repos/builtin/packages/nim/package.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/var/spack/repos/builtin/packages/nim/package.py b/var/spack/repos/builtin/packages/nim/package.py index 8f59e84b16f..f5db59f3349 100644 --- a/var/spack/repos/builtin/packages/nim/package.py +++ b/var/spack/repos/builtin/packages/nim/package.py @@ -105,9 +105,7 @@ class Nim(Package): phases = ["build", "install"] def patch(self): - """Hardcode dependency dynamic library paths into - wrapper modules using rpath.""" - + # Hardcode dependency dynamic library paths into wrapper modules using rpath def append_rpath(path, libdirs): """Add a pragma at the end of the file which passes rpath with libdirs to the linker when the module is used.""" @@ -133,6 +131,22 @@ def append_rpath(path, libdirs): if spec.satisfies("+sqlite"): append_rpath("lib/wrappers/sqlite3.nim", spec["sqlite"].libs.directories) + # Musl defines SysThread as a struct *pthread_t rather than an unsigned long as glibc does. + if self.spec.satisfies("^[virtuals=libc] musl"): + if self.spec.satisfies("@devel,1.9.3:"): + pthreadModule = "lib/std/private/threadtypes.nim" + elif self.spec.satisfies("@:0.19.6"): + pthreadModule = "lib/system/threads.nim" + else: + pthreadModule = "lib/system/threadlocalstorage.nim" + + filter_file( + 'header: "" .} = distinct culong', + 'header: "" .} = pointer', + pthreadModule, + string=True, + ) + def build(self, spec, prefix): if spec.satisfies("@devel"): with working_dir("csources_v2"):