Skip to content

Commit

Permalink
make_lib_rust - use position independent code (#334)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
lynxcs and mratsim committed Jan 9, 2024
1 parent df9034b commit 89d32a9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions constantine.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,13 @@ proc genDynamicLib(outdir, nimcache: string) =
else:
compile "libconstantine.so"

proc genStaticLib(outdir, nimcache: string) =
proc genStaticLib(outdir, nimcache: string, extFlags = "") =
proc compile(libName: string, flags = "") =
echo &"Compiling static library: {outdir}/" & libName

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

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

0 comments on commit 89d32a9

Please sign in to comment.