-
-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nim language support #1756
Comments
I have supported it. #1759 Consoleadd_rules("mode.debug", "mode.release")
target("test")
set_kind("binary")
add_files("src/main.nim") $ xmake -v
[ 33%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache -o:b
uild/macosx/x86_64/release/test src/main.nim
[100%]: build ok! Static Libraryadd_rules("mode.debug", "mode.release")
target("foo")
set_kind("static")
add_files("src/foo.nim")
target("test")
set_kind("binary")
add_deps("foo")
add_files("src/main.nim") $ xmake -v
[ 33%]: linking.release libfoo.a
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/foo/macosx/x86_64/release/nimcache --app
:staticlib --noMain --passC:-DNimMain=NimMain_B6D5BD02 --passC:-DNimMainInner=NimMainInner_B6D5B
D02 --passC:-DNimMainModule=NimMainModule_B6D5BD02 --passC:-DPreMain=PreMain_B6D5BD02 --passC:-D
PreMainInner=PreMainInner_B6D5BD02 -o:build/macosx/x86_64/release/libfoo.a src/foo.nim
[ 66%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache --pa
ssL:-Lbuild/macosx/x86_64/release --passL:-lfoo -o:build/macosx/x86_64/release/test src/main.nim
[100%]: build ok! For static libraries, there is currently a _NimMain symbol redefinition bug that needs to be fixed. At present, I can only fix it temporarily through the workaround solution. My workaround solution function buildargv(self, sourcefiles, targetkind, targetfile, flags)
local flags_extra = {}
if targetkind == "static" then
-- fix multiple definition of `NimMain', it is only workaround solution
-- we need to wait for this problem to be resolved
--
-- @see https://github.com/nim-lang/Nim/issues/15955
local uniquekey = hash.uuid(targetfile):split("-", {plain = true})[1]
table.insert(flags_extra, "--passC:-DNimMain=NimMain_" .. uniquekey)
table.insert(flags_extra, "--passC:-DNimMainInner=NimMainInner_" .. uniquekey)
table.insert(flags_extra, "--passC:-DNimMainModule=NimMainModule_" .. uniquekey)
table.insert(flags_extra, "--passC:-DPreMain=PreMain_" .. uniquekey)
table.insert(flags_extra, "--passC:-DPreMainInner=PreMainInner_" .. uniquekey)
end
return self:program(), table.join("c", flags, flags_extra, "-o:" .. targetfile, sourcefiles)
end Shared Libraryadd_rules("mode.debug", "mode.release")
target("foo")
set_kind("shared")
add_files("src/foo.nim")
target("test")
set_kind("binary")
add_deps("foo")
add_files("src/main.nim") $ xmake -rv
[ 33%]: linking.release libfoo.dylib
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/foo/macosx/x86_64/release/nimcache --app
:lib --noMain -o:build/macosx/x86_64/release/libfoo.dylib src/foo.nim
[ 66%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache --pa
ssL:-Lbuild/macosx/x86_64/release --passL:-lfoo -o:build/macosx/x86_64/release/test src/main.nim
[100%]: build ok! With C Libraryadd_rules("mode.debug", "mode.release")
target("foo")
set_kind("static")
add_files("src/*.c")
target("test")
set_kind("binary")
add_deps("foo")
add_files("src/main.nim") Use packagesadd_rules("mode.debug", "mode.release")
add_requires("zlib")
target("test")
set_kind("binary")
add_files("src/main.nim")
add_packages("zlib") main.nim proc zlibVersion(): cstring {.cdecl, importc}
echo zlibVersion() $ xmake -v
[ 33%]: linking.release test
/usr/local/bin/nim c --opt:speed --nimcache:build/.gens/test/macosx/x86_64/release/nimcache --pas
sL:-L/Users/ruki/.xmake/packages/z/zlib/1.2.11/b76a297309d14c09b42cfe3927260a51/lib --passL:-lz -
o:build/macosx/x86_64/release/test src/main.nim
[100%]: build ok!
$ xmake r
1.2.11 |
Some apis for nim
|
I will improve the package management to directly install and integrate packages from nimble later, for example: add_requires("nimble::zlib")
target("test")
set_kind("binary")
add_files("src/main.nim")
add_packages("nimble::zlib") However, even if there is no nimble yet, we can use xmake's package management to directly integrate the c/c++ package from xmake-repo/vcpkg/conan in the nim project. add_requires("zlib", "vcpkg::libpng")
target("test")
set_kind("binary")
add_files("src/main.nim")
add_packages("zlib", "vcpkg::libpng") |
More Examples: https://github.com/xmake-io/xmake/tree/dev/tests/projects/nim Project templates xmake create -l nim -t console test
xmake create -l nim -t static test
xmake create -l nim -t shared test |
We can use nimble packages now Nimble packageshttps://github.com/xmake-io/xmake/tree/dev/tests/projects/nim/nimble_package add_rules("mode.debug", "mode.release")
add_requires("nimble::zip >0.3")
target("test")
set_kind("binary")
add_files("src/main.nim")
add_packages("nimble::zip") main.nim import zip/zlib
echo zlibVersion() Native packageshttps://github.com/xmake-io/xmake/tree/dev/tests/projects/nim/native_package add_rules("mode.debug", "mode.release")
add_requires("zlib")
target("test")
set_kind("binary")
add_files("src/main.nim")
add_packages("zlib") main.nim proc zlibVersion(): cstring {.cdecl, importc}
echo zlibVersion() |
Nim is a compiled language that is as fast and efficient as C but with a python-like syntax and many other features. It compiles to native C code (just like C++ in the old days) but lately also to javascript.
I would love to see Nim support in xmake and would certainly use it for my Nim projects :)
Nim has its own
nimble
package/project manager which could be compared to rust'scargo
. I am not sure if in xmake we would implement support through nimble or bare nim compiler commands, or maybe both. But I guess the rust implementation could be a guideline.The text was updated successfully, but these errors were encountered: