Skip to content

Instantly share code, notes, and snippets.

@tothi
Last active May 13, 2023 12:21
Show Gist options
  • Save tothi/1f452e0466070db5921135ab312749fc to your computer and use it in GitHub Desktop.
Save tothi/1f452e0466070db5921135ab312749fc to your computer and use it in GitHub Desktop.
Nim config script for making Nim build compatible with Mingw-w64 (useful on ArchLinux setups because the defaults there break things)
# original idea: https://github.com/nim-lang/Nim/issues/20007#issue-1300915309
# use case for https://github.com/chvancooten/NimPlant
# - put this config.nims into NimPlant/client folder and build should work without errors on ArchLinux also
import std/strutils
import std/sequtils
# remove -fstack-clash-protection
switch("gcc.options.always", replace(get("gcc.options.always"), "-fstack-clash-protection", ""))
# disable _FORTIFY_SOURCE
switch("gcc.options.always", replace(get("gcc.options.always"), "-D_FORTIFY_SOURCE=2", "-D_FORTIFY_SOURCE=0"))
proc dropZ(f: string): string =
let flags = f.split(",")
var result: seq[string] = @[]
var drop = false
for f in flags:
if f == "-z":
drop = true
elif not drop:
result.add(f)
else:
drop = false
return result.join(",")
# remove all instance of -z flags and their parameters
let new_flags = get("gcc.options.linker").split(" ").map(dropZ).join(" ")
switch("gcc.options.linker", new_flags)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment