diff options
Diffstat (limited to '')
| -rw-r--r-- | config.nims | 60 | ||||
| -rw-r--r-- | nimble.paths | 1 | ||||
| -rw-r--r-- | tesserae.nimble | 13 |
3 files changed, 74 insertions, 0 deletions
diff --git a/config.nims b/config.nims new file mode 100644 index 0000000..2a7f6b4 --- /dev/null +++ b/config.nims @@ -0,0 +1,60 @@ +# begin Nimble config (version 2) +--noNimblePath +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" + +# The following sets up musl as an option for fully static binaries. +# It was found here +# https://scripter.co/nim-deploying-static-binaries/ +from macros import error +from ospaths import splitFile, `/` + +# -d:musl +when defined(musl): + var muslGccPath: string + echo " [-d:musl] Building a static binary using musl .." + muslGccPath = findExe("musl-gcc") + # echo "debug: " & muslGccPath + if muslGccPath == "": + error("'musl-gcc' binary was not found in PATH.") + switch("gcc.exe", muslGccPath) + switch("gcc.linkerexe", muslGccPath) + switch("passL", "-static") + +proc binOptimize(binFile: string) = + ## Optimize size of the ``binFile`` binary. + echo "" + if findExe("strip") != "": + echo "Running 'strip -s' .." + exec "strip -s " & binFile + if findExe("upx") != "": + # https://github.com/upx/upx/releases/ + echo "Running 'upx --best' .." + exec "upx --best " & binFile + +# nim musl foo.nim +task musl, "Builds an optimized static binary using musl": + ## Usage: nim musl <.nim file path> + let + numParams = paramCount() + if numParams != 2: + error("The 'musl' sub-command needs exactly 1 argument, the Nim file (but " & + $(numParams-1) & " were detected)." & + "\n Usage Example: nim musl FILE.nim.") + + let + nimFile = paramStr(numParams) ## The nim file name *must* be the last. + (dirName, baseName, _) = splitFile(nimFile) + binFile = dirName / baseName # Save the binary in the same dir as the nim file + nimArgs = "c -d:musl -d:release --opt:size " & nimFile + # echo "[debug] nimFile = " & nimFile & ", binFile = " & binFile + + # Build binary + echo "\nRunning 'nim " & nimArgs & "' .." + selfExec nimArgs + + # Optimize binary + binOptimize(binFile) + + echo "\nCreated binary: " & binFile +# end Nimble config diff --git a/nimble.paths b/nimble.paths new file mode 100644 index 0000000..48e67c1 --- /dev/null +++ b/nimble.paths @@ -0,0 +1 @@ +--noNimblePath diff --git a/tesserae.nimble b/tesserae.nimble new file mode 100644 index 0000000..6e0d88f --- /dev/null +++ b/tesserae.nimble @@ -0,0 +1,13 @@ +# Package + +version = "0.1.0" +author = "aethrvmn" +description = "nim implementation of package scripts" +license = "EUPL-1.2" +srcDir = "src" +bin = @["tesserae"] + + +# Dependencies + +requires "nim >= 2.2.4" |
