Skip to content

Commit 89d32a9

Browse files
lynxcsmratsim
andauthored
make_lib_rust - use position independent code (#334)
* make_lib_rust - compile with -fPIC * -fPIC: Windows is fully position independent, some compiler may error on -fPIC --------- Co-authored-by: Mamy Ratsimbazafy <[email protected]>
1 parent df9034b commit 89d32a9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

constantine.nimble

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,13 @@ proc genDynamicLib(outdir, nimcache: string) =
228228
else:
229229
compile "libconstantine.so"
230230

231-
proc genStaticLib(outdir, nimcache: string) =
231+
proc genStaticLib(outdir, nimcache: string, extFlags = "") =
232232
proc compile(libName: string, flags = "") =
233233
echo &"Compiling static library: {outdir}/" & libName
234234

235235
exec "nim c " &
236236
flags &
237+
extFlags &
237238
releaseBuildOptions(bmStaticLib) &
238239
" --threads:on " &
239240
" --noMain --app:staticlib " &
@@ -271,7 +272,10 @@ task make_lib, "Build Constantine library":
271272
task make_lib_rust, "Build Constantine library (use within a Rust build.rs script)":
272273
doAssert existsEnv"OUT_DIR", "Cargo needs to set the \"OUT_DIR\" environment variable"
273274
let rustOutDir = getEnv"OUT_DIR"
274-
genStaticLib(rustOutDir, rustOutDir/"nimcache")
275+
# Compile as position independent, since rust does the same by default
276+
let extflags = if defined(windows): "" # Windows is fully position independent, flag is a no-op or on error depending on compiler.
277+
else: "--passC:-fPIC"
278+
genStaticLib(rustOutDir, rustOutDir/"nimcache", extflags)
275279

276280
proc testLib(path, testName: string, useGMP: bool) =
277281
let dynlibName = if defined(windows): "constantine.dll"

0 commit comments

Comments
 (0)