compiler/ccgtypes: hide exportc proc unless it has dynlib (#13199)
This hides most of stdlib's internal functions from resulting binaries/libraries, where they aren't needed on *nix. Static libraries are not affected by this change (visibility doesn't apply to them).
This commit is contained in:
parent
da1bddb084
commit
470faa97c6
3 changed files with 24 additions and 1 deletions
|
|
@ -954,7 +954,7 @@ proc genProcHeader(m: BModule, prc: PSym, asPtr: bool = false): Rope =
|
||||||
result.add "N_LIB_EXPORT "
|
result.add "N_LIB_EXPORT "
|
||||||
elif prc.typ.callConv == ccInline or asPtr or isNonReloadable(m, prc):
|
elif prc.typ.callConv == ccInline or asPtr or isNonReloadable(m, prc):
|
||||||
result.add "static "
|
result.add "static "
|
||||||
elif {sfImportc, sfExportc} * prc.flags == {}:
|
elif sfImportc notin prc.flags:
|
||||||
result.add "N_LIB_PRIVATE "
|
result.add "N_LIB_PRIVATE "
|
||||||
var check = initIntSet()
|
var check = initIntSet()
|
||||||
fillLoc(prc.loc, locProc, prc.ast[namePos], mangleName(m, prc), OnUnknown)
|
fillLoc(prc.loc, locProc, prc.ast[namePos], mangleName(m, prc), OnUnknown)
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,9 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
|
||||||
var test3 = makeTest("lib/nimhcr.nim", options & " --outdir:tests/dll" & rpath, cat)
|
var test3 = makeTest("lib/nimhcr.nim", options & " --outdir:tests/dll" & rpath, cat)
|
||||||
test3.spec.action = actionCompile
|
test3.spec.action = actionCompile
|
||||||
testSpec c, test3
|
testSpec c, test3
|
||||||
|
var test4 = makeTest("tests/dll/visibility.nim", options & " --app:lib" & rpath, cat)
|
||||||
|
test4.spec.action = actionCompile
|
||||||
|
testSpec c, test4
|
||||||
|
|
||||||
# windows looks in the dir of the exe (yay!):
|
# windows looks in the dir of the exe (yay!):
|
||||||
when not defined(Windows):
|
when not defined(Windows):
|
||||||
|
|
@ -141,6 +144,7 @@ proc runBasicDLLTest(c, r: var TResults, cat: Category, options: string) =
|
||||||
|
|
||||||
testSpec r, makeTest("tests/dll/client.nim", options & " --threads:on" & rpath, cat)
|
testSpec r, makeTest("tests/dll/client.nim", options & " --threads:on" & rpath, cat)
|
||||||
testSpec r, makeTest("tests/dll/nimhcr_unit.nim", options & rpath, cat)
|
testSpec r, makeTest("tests/dll/nimhcr_unit.nim", options & rpath, cat)
|
||||||
|
testSpec r, makeTest("tests/dll/visibility.nim", options & rpath, cat)
|
||||||
|
|
||||||
if "boehm" notin options:
|
if "boehm" notin options:
|
||||||
# force build required - see the comments in the .nim file for more details
|
# force build required - see the comments in the .nim file for more details
|
||||||
|
|
|
||||||
19
tests/dll/visibility.nim
Normal file
19
tests/dll/visibility.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
discard """
|
||||||
|
output: "could not import: foo"
|
||||||
|
exitcode: 1
|
||||||
|
"""
|
||||||
|
|
||||||
|
const LibName {.used.} =
|
||||||
|
when defined(windows):
|
||||||
|
"visibility.dll"
|
||||||
|
elif defined(macosx):
|
||||||
|
"libvisibility.dylib"
|
||||||
|
else:
|
||||||
|
"libvisibility.so"
|
||||||
|
|
||||||
|
when compileOption("app", "lib"):
|
||||||
|
proc foo() {.exportc.} =
|
||||||
|
echo "failed"
|
||||||
|
elif isMainModule:
|
||||||
|
proc foo() {.importc, dynlib: LibName.}
|
||||||
|
foo()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue