Skip to content

enhance Nim support for shared libraries and rpath handling#7272

Merged
waruqi merged 27 commits intoxmake-io:devfrom
luadebug:nimlib
Jan 31, 2026
Merged

enhance Nim support for shared libraries and rpath handling#7272
waruqi merged 27 commits intoxmake-io:devfrom
luadebug:nimlib

Conversation

@luadebug
Copy link
Member

@luadebug luadebug commented Jan 27, 2026

Lets assume we have got static and shared library to link against for our executable. It looks like this won't build if we do not help Linux to figure out where is linkdir to check for so files... :(

Well at least static library is being linked and works without issues. I am prolly lack of Windows/MacOS environment to check.

xmake run executableshared
checking for platform ... linux
checking for architecture ... x86_64
[ 15%]: linking.release libsharedlib.so
[ 15%]: linking.release libstaticlib.a
[ 39%]: linking.release executablestaic
[ 63%]: linking.release executableshared
[100%]: build ok, spent 6,511s
/home/lin/xmake-luadebug/tests/projects/nim/link_library/build/linux/x86_64/release/executableshared: error while loading shared libraries: libsharedlib.so: cannot open shared object file: No such file or directory
error: execv(/home/lin/xmake-luadebug/tests/projects/nim/link_library/build/linux/x86_64/release/executableshared ) failed(127)

#6488 mentions 3rd option is --passL:"..."

So I tried to extract current flags:

  1. Static library example:
[ 15%]: linking.debug libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/staticlib/linux/x86_64/debug/nimcache --app:staticlib --noMain --debugger:native --nimMainPrefix:libstatic -o:build/linux/x86_64/debug/libstaticlib.a static.nim
[ 63%]: linking.debug executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/executablestatic/linux/x86_64/debug/nimcache --passL:-Lbuild/linux/x86_64/debug --debugger:native --passL:-lstaticlib -o:build/linux/x86_64/debug/executablestatic mainlib.nim
  1. Shared library example:
[ 15%]: linking.debug libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/sharedlib/linux/x86_64/debug/nimcache --app:lib --noMain --debugger:native -o:build/linux/x86_64/debug/libsharedlib.so shared.nim
[ 63%]: linking.debug executableshared
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/executableshared/linux/x86_64/debug/nimcache --passL:-Lbuild/linux/x86_64/debug --debugger:native --passL:-lsharedlib -o:build/linux/x86_64/debug/executableshared maindll.nim

Once we apply "..." wrapper... flags would change a little bit:

[ 15%]: linking.debug libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/sharedlib/linux/x86_64/debug/nimcache --app:lib --noMain --debugger:native -o:build/linux/x86_64/debug/libsharedlib.so shared.nim
checking for the nim compiler (nc) ... nim
[ 15%]: linking.debug libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/staticlib/linux/x86_64/debug/nimcache --app:staticlib --noMain --debugger:native --nimMainPrefix:libstatic -o:build/linux/x86_64/debug/libstaticlib.a static.nim
[ 39%]: linking.debug executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/executablestatic/linux/x86_64/debug/nimcache --passL:\"-Lbuild/linux/x86_64/debug\" --debugger:native --passL:\"-lstaticlib\" -o:build/linux/x86_64/debug/executablestatic mainlib.nim
[ 63%]: linking.debug executableshared
/usr/bin/nim c --debugger:native --opt:none --nimcache:build/.gens/executableshared/linux/x86_64/debug/nimcache --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-Wl,-rpath=build/linux/x86_64/debug\" --passL:\"-Lbuild/linux/x86_64/debug\" --passL:\"-Wl,-rpath=\$ORIGIN\" --debugger:native --passL:\"-lsharedlib\" -o:build/linux/x86_64/debug/executableshared maindll.nim

I have noticed that I was unable to build x86 executable... :( So I had to enforce cpu via --cpu:%ARCH% flag. So it would produce x86 executable instead of x64 executable.

xmake f -m debug -a x86 && xmake -rvD && cd ..
checking for platform ... linux
checking for /usr/bin/nim ... ok
checking for the nim compiler (nc) ... nim
checking for /usr/bin/nim ... ok
checking for flags (--opt:none) ... ok
> nim "--opt:none" "--cpu:i386" "--define:bit32" "--passC:"-m32"" "--passL:"-m32""
[ 15%]: linking.debug libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --cpu:i386 --define:bit32 --passC:\"-m32\" --passL:\"-m32\" --debugger:native --opt:none --nimcache:build/.gens/sharedlib/linux/x86/debug/nimcache --app:lib --noMain --cpu:i386 --define:bit32 --passC:\"-m32\" --passL:\"-m32\" --debugger:native -o:build/linux/x86/debug/libsharedlib.so shared.nim
checking for the nim compiler (nc) ... nim
[ 15%]: linking.debug libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --cpu:i386 --define:bit32 --passC:\"-m32\" --passL:\"-m32\" --debugger:native --opt:none --nimcache:build/.gens/staticlib/linux/x86/debug/nimcache --app:staticlib --noMain --cpu:i386 --define:bit32 --debugger:native --nimMainPrefix:libstatic -o:build/linux/x86/debug/libstaticlib.a static.nim
[ 39%]: linking.debug executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --cpu:i386 --define:bit32 --passC:\"-m32\" --passL:\"-m32\" --debugger:native --opt:none --nimcache:build/.gens/executablestatic/linux/x86/debug/nimcache --passL:\"-Lbuild/linux/x86/debug\" --debugger:native --passL:\"-lstaticlib\" -o:build/linux/x86/debug/executablestatic mainlib.nim
[ 63%]: linking.debug executableshared
/usr/bin/nim c --cpu:i386 --define:bit32 --passC:\"-m32\" --passL:\"-m32\" --debugger:native --opt:none --nimcache:build/.gens/executableshared/linux/x86/debug/nimcache --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-Wl,-rpath=build/linux/x86/debug\" --passL:\"-Lbuild/linux/x86/debug\" --passL:\"-Wl,-rpath=\$ORIGIN\" --debugger:native --passL:\"-lsharedlib\" -o:build/linux/x86/debug/executableshared maindll.nim

Without my last commit a9761dd it would not see headerfile at all from binary files perspective... #include "test.h"

…rms; add Nim test files for static and shared libraries
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @luadebug, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical issue where executables linked against shared libraries failed to run on Linux due to an inability to locate the libraries at runtime. The core change involves refactoring the runpath environment variable handling to be platform-agnostic. Previously limited to Windows' PATH, the system now correctly applies LD_LIBRARY_PATH for Linux and DYLD_LIBRARY_PATH for macOS, ensuring proper shared library discovery across these operating systems. Additionally, new Nim-based test cases have been introduced to thoroughly validate the updated linking behavior for both static and shared libraries.

Highlights

  • Refactored Runpath Function: The _make_runpath_on_windows function has been generalized and renamed to _make_runpath to support multiple platforms, accepting an envname parameter.
  • Cross-Platform Shared Library Linking: The runpath logic now correctly sets LD_LIBRARY_PATH for Linux and DYLD_LIBRARY_PATH for macOS, resolving issues with shared library discovery on these operating systems.
  • New Nim Test Cases: A new test project for the Nim language has been added, demonstrating the linking of both static and shared libraries to validate the updated runpath functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the _make_runpath_on_windows function into a more generic _make_runpath to support shared library runpaths across multiple platforms, including Linux and macOS, by correctly setting LD_LIBRARY_PATH or DYLD_LIBRARY_PATH. The addition of Nim test cases for static and shared library linking is a good step to validate this new functionality. However, there's a potential issue in how addenvs and setenvs are managed, which could lead to unintended modifications of setenvs or incorrect application of runpath values.

@luadebug luadebug changed the title refactor: update runpath function and add support for multiple platforms enhance Nim support for shared libraries and rpath handling Jan 27, 2026
if self:is_plat("linux", "macosx", "bsd") then
if level == "debug" or level == "all" then
return "--passL:-s"
return "--passL:\"-s\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous configuration is not working?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that only flags containing spaces need to be enclosed in double quotes.

Copy link
Member Author

@luadebug luadebug Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aw I am confused over this step. Maybe it should be like --passL:"-s" but no matter what it keeps applying before " the \ symbol... Feel free to adjust to your like.
That stuff works but it was not wrapped into "" for safety, that is what Ive assumed.

add_files("mainlib.nim")
add_deps("staticlib")
add_packages("zlib", "stb")
add_syslinks("pthread", "m")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two libraries required? Do the dependencies require them? These two libraries are not compiling on Windows.

Copy link
Member Author

@luadebug luadebug Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my oversight... They are not required, I was just testing on my Linux and forgor about that.

@waruqi
Copy link
Member

waruqi commented Jan 29, 2026

It does not work on macOS.

checking for /usr/local/bin/nim ... ok
checking for the nim compiler (nc) ... nim
checking for /usr/local/bin/nim ... ok
checking for flags (-d:release) ... ok
[ 27%]: linking.release libsharedlib.dylib
checking for /usr/local/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/local/bin/nim c -d:release --passC:-Iinc --nimcache:build/.gens/sharedlib/macosx/x86_64/release/nimcache --app:lib --noMain --passL:-s -o:build/macosx/x8
6_64/release/libsharedlib.dylib shared.nim
checking for the nim compiler (nc) ... nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/local/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/local/bin/nim c -d:release --passC:-Iinc --nimcache:build/.gens/staticlib/macosx/x86_64/release/nimcache --app:staticlib --noMain --passL:-s --nimMainPre
fix:libstatic -o:build/macosx/x86_64/release/libstaticlib.a static.nim
error: Hint: used config file '/usr/local/Cellar/nim/2.2.6/nim/config/nim.cfg' [Conf]
Hint: used config file '/usr/local/Cellar/nim/2.2.6/nim/config/config.nims' [Conf]
......................................................................
CC: system/exceptions.nim
CC: std/private/digitsutils.nim
CC: system/dollars.nim
CC: system.nim
CC: static.nim
/Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/staticlib/macosx/x86_64/release/nimcache/@mstatic.nim.c:36:10: fatal error: 't
est_header.h' file not found
   36 | #include <test_header.h>
      |          ^~~~~~~~~~~~~~~
1 error generated.
Error: execution of an external compiler program 'clang -c  -w -ferror-limit=3 -fno-strict-aliasing -pthread -Iinc -O3   -I/usr/local/Cellar/nim/2.2.6/nim/lib
 -I/Users/ruki/projects/personal/xmake/tests/projects/nim/link_library -o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/stat
iclib/macosx/x86_64/release/nimcache/@mstatic.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/staticlib/macosx/x86_64/
release/nimcache/@mstatic.nim.c' failed with exit code: 1

@luadebug
Copy link
Member Author

luadebug commented Jan 29, 2026

It does not work on macOS.

checking for /usr/local/bin/nim ... ok
checking for the nim compiler (nc) ... nim
checking for /usr/local/bin/nim ... ok
checking for flags (-d:release) ... ok
[ 27%]: linking.release libsharedlib.dylib
checking for /usr/local/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/local/bin/nim c -d:release --passC:-Iinc --nimcache:build/.gens/sharedlib/macosx/x86_64/release/nimcache --app:lib --noMain --passL:-s -o:build/macosx/x8
6_64/release/libsharedlib.dylib shared.nim
checking for the nim compiler (nc) ... nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/local/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/local/bin/nim c -d:release --passC:-Iinc --nimcache:build/.gens/staticlib/macosx/x86_64/release/nimcache --app:staticlib --noMain --passL:-s --nimMainPre
fix:libstatic -o:build/macosx/x86_64/release/libstaticlib.a static.nim
error: Hint: used config file '/usr/local/Cellar/nim/2.2.6/nim/config/nim.cfg' [Conf]
Hint: used config file '/usr/local/Cellar/nim/2.2.6/nim/config/config.nims' [Conf]
......................................................................
CC: system/exceptions.nim
CC: std/private/digitsutils.nim
CC: system/dollars.nim
CC: system.nim
CC: static.nim
/Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/staticlib/macosx/x86_64/release/nimcache/@mstatic.nim.c:36:10: fatal error: 't
est_header.h' file not found
   36 | #include <test_header.h>
      |          ^~~~~~~~~~~~~~~
1 error generated.
Error: execution of an external compiler program 'clang -c  -w -ferror-limit=3 -fno-strict-aliasing -pthread -Iinc -O3   -I/usr/local/Cellar/nim/2.2.6/nim/lib
 -I/Users/ruki/projects/personal/xmake/tests/projects/nim/link_library -o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/stat
iclib/macosx/x86_64/release/nimcache/@mstatic.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/staticlib/macosx/x86_64/
release/nimcache/@mstatic.nim.c' failed with exit code: 1

Why it did not wrap flags into \"...\" at this example.

@waruqi
Copy link
Member

waruqi commented Jan 29, 2026

My mistake, I used incorrect xmake version.

But it does not work.

/Users/ruki/projects/personal/xmake/tests/projects/nim/link_library
ruki:link_library ruki$ xmake f -c
checking for platform ... macosx
checking for architecture ... x86_64
checking for Xcode directory ... /Applications/Xcode.app
checking for SDK version of Xcode for macosx (x86_64) ... 15.2
checking for Minimal target version of Xcode for macosx (x86_64) ... 15.2
updating repositories .. ok
ruki:link_library ruki$ xmake -rv
checking for /usr/local/bin/nim ... ok
checking for the nim compiler (nc) ... nim
checking for /usr/local/bin/nim ... ok
checking for the nim compiler (nc) ... nim
checking for flags (-d:release) ... ok
[ 27%]: linking.release libsharedlib.dylib
checking for /usr/local/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/local/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/sharedlib/macosx/x86_64/release/nimcache --passC:\"-Iheade
rs\" --app:lib --noMain --passL:\"-s\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/macosx/x86_64/release/libshare
dlib.dylib shared.nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/local/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/local/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/staticlib/macosx/x86_64/release/nimcache --passC:\"-Iheade
rs\" --app:staticlib --noMain --passL:\"-s\" --nimMainPrefix:libstatic -o:build/macosx/x86_64/release/libstaticlib.a static.nim
[ 47%]: linking.release executablestatic
checking for /usr/local/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/local/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executablestatic/macosx/x86_64/release/nimcache --passC:\"-I/Users/ruki/.xma
ke/packages/z/zlib/v1.3.1/3323a56e4f3c40c2895f732924aff059/include\" --passL:\"-L/Users/ruki/.xmake/packages/z/zlib/v1.3.1/3323a56e4f3c40c2895f732924aff059/li
b\" --passL:\"-lz\" --passC:\"-I/Users/ruki/.xmake/packages/s/stb/2025.03.14/aa287dcb4c2b4e16a25c6aaf2eee6e26/include\" --passC:\"-I/Users/ruki/.xmake/package
s/s/stb/2025.03.14/aa287dcb4c2b4e16a25c6aaf2eee6e26/include/stb\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-L/Users/ruki/.xmake/packages/z/zlib/v1.3.
1/3323a56e4f3c40c2895f732924aff059/lib\" --passL:\"-Lbuild/macosx/x86_64/release\" --passL:\"-s\" --passL:\"-lz\" --passL:\"-lstaticlib\" --threads:on --passL
:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/macosx/x86_64/release/executablestatic mainlib.nim
[ 67%]: linking.release executableshared
/usr/local/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executableshared/macosx/x86_64/release/nimcache --passL:\"-Wl,-rpath=build/m
acosx/x86_64/release\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-Lbuild/macosx/x86_64/release\" --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-s\" --pass
L:\"-lsharedlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/macosx/x86_64/release/executableshared maindll.nim
error: Hint: used config file '/usr/local/Cellar/nim/2.2.6/nim/config/nim.cfg' [Conf]
Hint: used config file '/usr/local/Cellar/nim/2.2.6/nim/config/config.nims' [Conf]
..............................................................................................
CC: system/exceptions.nim
CC: std/private/digitsutils.nim
CC: std/assertions.nim
CC: system/dollars.nim
CC: system.nim
CC: hashes.nim
CC: math.nim
CC: tables.nim
CC: strutils.nim
CC: shared.nim
CC: maindll.nim
Hint:  [Link]
ld: warning: -s is obsolete
ld: unknown options: -rpath=build/macosx/x86_64/release -rpath=$ORIGIN
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of an external program failed: 'clang   -o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/macosx/x86_64/release/ex
ecutableshared  /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@psystem@sexce
ptions.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@pstd@sprivate@
sdigitsutils.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@pstd@sas
sertions.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@psystem@sdol
lars.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@psystem.nim.c.o
/Users/ruki/projects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@phashes.nim.c.o /Users/ruki/p
rojects/personal/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@pmath.nim.c.o /Users/ruki/projects/persona
l/xmake/tests/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@ptables.nim.c.o /Users/ruki/projects/personal/xmake/tests
/projects/nim/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@pstrutils.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/n
im/link_library/build/.gens/executableshared/macosx/x86_64/release/nimcache/@mshared.nim.c.o /Users/ruki/projects/personal/xmake/tests/projects/nim/link_libra
ry/build/.gens/executableshared/macosx/x86_64/release/nimcache/@mmaindll.nim.c.o   "-Wl,-rpath=build/macosx/x86_64/release" "-Lbuild/macosx/x86_64/release" "-
Wl,-rpath=\$ORIGIN" "-s" "-lsharedlib" "-lpthread" "-lm"  -ldl'

@luadebug
Copy link
Member Author

Lets assume we would swap -rpath=$ORIGIN to -rpath $ORIGIN in your flags collection does it advance further?

@waruqi
Copy link
Member

waruqi commented Jan 29, 2026

Lets assume we would swap -rpath=$ORIGIN to -rpath $ORIGIN in your flags collection does it advance further?

On macOS, we need to additionally pass -Xlinker, and we need to replace $ORIGIN.

elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir, "ldflags") then
return {"-Xlinker", "-rpath", "-Xlinker", (dir:gsub("%$ORIGIN", "@loader_path"))}

@luadebug
Copy link
Member Author

luadebug commented Jan 30, 2026

I think updating nim from 2.0.8 of yay's repo to pixi's repo 2.2.8 has caused:
/home/lin/xmake-luadebug/tests/projects/nim/link_library/build/linux/x86_64/debug/executableshared: CPU ISA level is lower than required...
So I assume newer nim maybe caused all of that.

❯ xmake l os.cpuinfo
{ 
  march = "Ivy Bridge",
  usagerate = 0,0,
  model_name = "Intel(R) Xeon(R) CPU E5-2697 v2 @ 2.70GHz",
  family = 6,
  features = "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti ssbd ibrs ibpb stibp tpr_shadow flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts vnmi md_clear flush_l1d",
  ncpu = 48,
  model = 62,
  vendor = "GenuineIntel" 
}

Alright this wors now... As I switched back to yay's nim 2.0.8

install ok!
finding zlib from xmake ..
checking for xmake::zlib ... zlib v1.3.1
{ 
  license = "zlib",
  links = { 
    "z" 
  },
  libfiles = { 
    "/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib/libz.so" 
  },
  shared = true,
  sysincludedirs = { 
    "/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/include" 
  },
  version = "v1.3.1",
  linkdirs = { 
    "/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib" 
  } 
}

patching /home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib/pkgconfig/zlib.pc ..
checking for gcc ... /usr/bin/gcc
checking for the c compiler (cc) ... gcc
checking for /usr/bin/gcc ... ok
checking for flags (-fPIC) ... ok
> gcc "-fPIC" "-m64"
> /usr/bin/gcc -c -m64 -isystem /home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/include -o /tmp/.xmake1000/260130/_b9b141053da614167acb156483660bde.o /tmp/.xmake1000/260130/_3f3459176319d6f1b4316b5924b31e21.c
checking for flags (-fdiagnostics-color=always) ... ok
> gcc "-fdiagnostics-color=always" "-m64"
checking for flags (-Wno-gnu-line-marker -Werror) ... ok
> gcc "-Wno-gnu-line-marker" "-Werror" "-m64"
checking for g++ ... /usr/bin/g++
checking for the linker (ld) ... g++
checking for /usr/bin/g++ ... ok
checking for flags (-fPIC) ... ok
> g++ "-fPIC" "-m64" "-m64"
> /usr/bin/g++ -o /tmp/.xmake1000/260130/_b9b141053da614167acb156483660bde.b /tmp/.xmake1000/260130/_b9b141053da614167acb156483660bde.o -m64 -L/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib -lz
> checking for c includes(zlib.h)
> checking for c funcs(inflate)
> checking for c links(z)
> checking for c snippet(has_cfuncs)
  => install zlib v1.3.1 .. ok
/usr/bin/git -c core.fsmonitor=false clean -d -f -x
/usr/bin/git -c core.fsmonitor=false reset --hard
HEAD is now at f056911 update stb_image_resize2.h
finding stb from xmake ..
checking for xmake::stb ... stb 2025.03.14
{ 
  sysincludedirs = { 
    "/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include",
    "/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb" 
  },
  version = "2025.03.14" 
}

patching /home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/lib/pkgconfig/stb.pc ..
> /usr/bin/gcc -c -m64 -isystem /home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include -isystem /home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb -o /tmp/.xmake1000/260130/_85f6b46782c82421ab3068e9b06c0a00.o /tmp/.xmake1000/260130/_cd962eb44872fa135af268a89d490b10.c
> checking for c includes(stb/stb_image.h)
> checking for c funcs(stbi_load_from_memory)
> checking for c snippet(has_cfuncs)
> /usr/bin/gcc -c -m64 -isystem /home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include -isystem /home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb -o /tmp/.xmake1000/260130/_f0ae306ae15633d4d627e043546678cb.o /tmp/.xmake1000/260130/_54f30e01877f5d12659bca0a33ba17f2.c
> checking for c includes(stb/stb_include.h)
> checking for c funcs(stb_include_string)
> checking for c snippet(has_cfuncs)
  => install stb 2025.03.14 .. ok
checking for /usr/bin/nim ... ok
checking for the nim compiler (nc) ... nim
checking for /usr/bin/nim ... ok
checking for flags (-d:release) ... ok
> nim "-d:release" "--cpu:amd64" "--define:bit64"
[ 27%]: linking.release libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/sharedlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:lib --noMain --passL:\"-s\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/libsharedlib.so shared.nim
checking for the nim compiler (nc) ... nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/staticlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:staticlib --noMain --passL:\"-s\" --nimMainPrefix:libstatic -o:build/linux/x86_64/release/libstaticlib.a static.nim
[ 47%]: linking.release executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executablestatic/linux/x86_64/release/nimcache --passC:\"-I/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/include\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib\" --passL:\"-lz\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-s\" --passL:\"-lz\" --passL:\"-lstaticlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executablestatic mainlib.nim
[ 67%]: linking.release executableshared
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executableshared/linux/x86_64/release/nimcache --passL:\"-Wl,-rpath=build/linux/x86_64/release\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-s\" --passL:\"-lsharedlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executableshared maindll.nim

build cache stats:
cache directory: /home/lin/xmake-luadebug/tests/projects/nim/link_library/build/.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0,000s
cache miss: 3
cache miss total time: 0,000s
new cached files: 3
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0,081s

[100%]: build ok, spent 11,107s
warning: add_requires("zlib") has unknown option: {config=table: 0x5641a45d4f00}!
TEST_HEADER_VAL: 123
test_add_five(10): 15
Calling shared lib mulTwo(10): 20
Calling shared lib countWords('hello, world, hello'): The most frequent word is '(key: "hello", val: 2)'
Calling shared lib getMsg('test'): Hello from Shared Lib!
TEST_HEADER_VAL: 123
test_add_five(80): 85
TEST_HEADER_VAL: 123
test_add_five(60): 65
Zlib Version: 1.3.1
STB Image: Flip vertically on load set to 1
Calling static lib addTwo(10): 12
Calling static lib getAlphabet(): abcdefghijklmnopqrstuvwxyz
Calling shared lib getMsg('test'): Hello from Static Lib!
TEST_HEADER_VAL: 123
test_add_five(55): 60

Switching zlib back from shared to static validates the result that all is fine:

[ 27%]: linking.release libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/sharedlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:lib --noMain --passL:\"-s\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/libsharedlib.so shared.nim
checking for the nim compiler (nc) ... nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/staticlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:staticlib --noMain --passL:\"-s\" --nimMainPrefix:libstatic -o:build/linux/x86_64/release/libstaticlib.a static.nim
[ 47%]: linking.release executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executablestatic/linux/x86_64/release/nimcache --passC:\"-I/home/lin/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/include\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/lib\" --passL:\"-lz\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/lib\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-s\" --passL:\"-lz\" --passL:\"-lstaticlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executablestatic mainlib.nim
[ 67%]: linking.release executableshared
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executableshared/linux/x86_64/release/nimcache --passL:\"-Wl,-rpath=build/linux/x86_64/release\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-s\" --passL:\"-lsharedlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executableshared maindll.nim

build cache stats:
cache directory: /home/lin/xmake-luadebug/tests/projects/nim/link_library/build/.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0,000s
cache miss: 3
cache miss total time: 0,001s
new cached files: 3
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0,081s

[100%]: build ok, spent 10,643s
warning: add_requires("zlib") has unknown option: {config=table: 0x564c0b7ca0e0}!
TEST_HEADER_VAL: 123
test_add_five(10): 15
Calling shared lib mulTwo(10): 20
Calling shared lib countWords('hello, world, hello'): The most frequent word is '(key: "hello", val: 2)'
Calling shared lib getMsg('test'): Hello from Shared Lib!
TEST_HEADER_VAL: 123
test_add_five(80): 85
TEST_HEADER_VAL: 123
test_add_five(60): 65
Zlib Version: 1.3.1
STB Image: Flip vertically on load set to 1
Calling static lib addTwo(10): 12
Calling static lib getAlphabet(): abcdefghijklmnopqrstuvwxyz
Calling shared lib getMsg('test'): Hello from Static Lib!
TEST_HEADER_VAL: 123
test_add_five(55): 60

set_project("link_libs")
add_rules("mode.debug", "mode.release")

add_requires("zlib", {system = false, config = {shared = true}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configs

warning: add_requires("zlib") has unknown option: {config=table: 0x600001918740}!

Copy link
Member Author

@luadebug luadebug Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks it works.

[ 27%]: linking.release libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/sharedlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:lib --noMain --passL:\"-s\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/libsharedlib.so shared.nim
checking for the nim compiler (nc) ... nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/staticlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:staticlib --noMain --passL:\"-s\" --nimMainPrefix:libstatic -o:build/linux/x86_64/release/libstaticlib.a static.nim
[ 47%]: linking.release executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executablestatic/linux/x86_64/release/nimcache --passC:\"-I/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/include\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib\" --passL:\"-lz\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/26943dc7c5a74a63bede41ae03809796/lib\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-s\" --passL:\"-lz\" --passL:\"-lstaticlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executablestatic mainlib.nim
[ 67%]: linking.release executableshared
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executableshared/linux/x86_64/release/nimcache --passL:\"-Wl,-rpath=build/linux/x86_64/release\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-s\" --passL:\"-lsharedlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executableshared maindll.nim

with static zlib

[ 27%]: linking.release libsharedlib.so
checking for /usr/bin/nim ... ok
checking for the nim shared library linker (ncsh) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/sharedlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:lib --noMain --passL:\"-s\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/libsharedlib.so shared.nim
checking for the nim compiler (nc) ... nim
[ 27%]: linking.release libstaticlib.a
checking for /usr/bin/nim ... ok
checking for the nim static library archiver (ncar) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --passC:\"-Iinc\" --nimcache:build/.gens/staticlib/linux/x86_64/release/nimcache --passC:\"-Iheaders\" --app:staticlib --noMain --passL:\"-s\" --nimMainPrefix:libstatic -o:build/linux/x86_64/release/libstaticlib.a static.nim
[ 47%]: linking.release executablestatic
checking for /usr/bin/nim ... ok
checking for the nim linker (ncld) ... nim
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executablestatic/linux/x86_64/release/nimcache --passC:\"-I/home/lin/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/include\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/lib\" --passL:\"-lz\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include\" --passC:\"-I/home/lin/.xmake/packages/s/stb/2025.03.14/67005fc11486400896028eb775a57270/include/stb\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-L/home/lin/.xmake/packages/z/zlib/v1.3.1/994fafa590ed48ac9f71516cc846d155/lib\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-s\" --passL:\"-lz\" --passL:\"-lstaticlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executablestatic mainlib.nim
[ 67%]: linking.release executableshared
/usr/bin/nim c --cpu:amd64 --define:bit64 -d:release --nimcache:build/.gens/executableshared/linux/x86_64/release/nimcache --passL:\"-Wl,-rpath=build/linux/x86_64/release\" --passC:\"-Iheaders\" --passC:\"-Iinc\" --passL:\"-Lbuild/linux/x86_64/release\" --passL:\"-Wl,-rpath=\$ORIGIN\" --passL:\"-s\" --passL:\"-lsharedlib\" --threads:on --passL:\"-lpthread\" --dynlibOverride:\"pthread\" --passL:\"-lm\" -o:build/linux/x86_64/release/executableshared maindll.nim

local pkg_includedirs = pkg:get("includedirs")
if pkg_includedirs then
for _, dir in ipairs(pkg_includedirs) do
local includeflags = compinst:_tool():nf_includedir(dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use compiler.map_flags or compinst:map_flags

function builder:map_flags(name, values, opt)

table.join2(flags, compiler.map_flags("cxx", "define", _get_values_from_target(target, "defines")))
local pathmaps = {
{"includedirs", "includedir"},
{"sysincludedirs", "includedir"}, -- for now, moc process doesn't support MSVC external includes flags and will fail
{"frameworkdirs", "frameworkdir"}
}
for _, pathmap in ipairs(pathmaps) do
for _, item in ipairs(_get_values_from_target(target, pathmap[1])) do
local pathitem = path(item, function (p)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we should use target:get_from to get values from target (deps, packages, ...)

-- get values from target
-- @see https://github.com/xmake-io/xmake/issues/3930
local function _get_values_from_target(target, name)
local values = {}
for _, value in ipairs((target:get_from(name, "*"))) do
table.join2(values, value)
end
return table.unique(values)

local pkg_linkdirs = pkg:get("linkdirs")
if pkg_linkdirs then
for _, dir in ipairs(pkg_linkdirs) do
local linkflags = compinst:_tool():nf_linkdir(dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

-- deduplicate
includedirs = table.unique(includedirs)
for _, includedir in ipairs(includedirs) do
local includeflags = compinst:_tool():nf_includedir(includedir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to remove all private api calls. compinst:_tool()

local rpathdirs_wrap = {}

-- add rpathdirs from dependencies
if target:kind() == "binary" or target:kind() == "shared" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target:is_binary(), target:is_shared()

-- we need pass includedirs of static/shared lib to the target
local includedirs = {}
for _, dep in ipairs(target:orderdeps()) do
if dep:kind() == "static" or dep:kind() == "shared" or dep:kind() == "headeronly" then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dep:is_headeronly()

add_rules("mode.debug", "mode.release")

add_requires("zlib", {system = false, configs = {shared = true}})
add_requires("zlib", {system = false, configs = {shared = false}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default shared config is false, you can remove this configs

add_deps("staticlib")
add_packages("zlib", "stb")
if is_plat("linux") then
add_syslinks("pthread", "m")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these package dependencies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I just added that to validate syslinks behavior. As it used to be ignore add_syslinks.

end

-- add dependency flags
function _add_dependency_flags(target, compinst, compflags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding these flags here is incorrect; it completely bypasses the logic of xmake compiler.compflags in retrieving flags, which is a rather hacky implementation.

We simply need to add the missing named flags item to languages/nim/xmake.lua

target("headers")
set_kind("headeronly")
add_files("headers/*.h")
add_includedirs("headers")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation does not follow the visibility logic of add_includedirs("xxx", {public = true})

set_kind("binary")
add_files("mainlib.nim")
add_deps("staticlib")
add_packages("zlib", "stb")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here. {public = true}

Currently, they are all privately visible, but other targets can still access their includedirs.

@waruqi
Copy link
Member

waruqi commented Jan 30, 2026

I refactored some incorrect implementations; you can try this patch.

#7279

changes: 83076f3


target("headers")
set_kind("headeronly")
add_files("headers/*.h")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and it should be add_headerfiles("header/*.h")

@luadebug
Copy link
Member Author

I refactored some incorrect implementations; you can try this patch.

#7279

changes: 83076f3

Thank you for improvements, this works just fine.

@waruqi waruqi merged commit 09a670d into xmake-io:dev Jan 31, 2026
35 checks passed
@waruqi waruqi added this to the v3.0.7 milestone Jan 31, 2026
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.

2 participants