Skip to content
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

make_lib_rust - use position independent code #334

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading