Skip to content
Browse files

implemented --dynlibOverride option for static linking of 'dynlib'

  • Loading branch information...
1 parent 8cd4e1a commit 94becd0de19c48be3b6393778b6526525a9ea887 @Araq Araq committed
Showing with 34 additions and 3 deletions.
  1. +1 −0 compiler/ast.nim
  2. +7 −0 compiler/commands.nim
  3. +15 −0 compiler/options.nim
  4. +5 −2 compiler/pragmas.nim
  5. +5 −0 doc/advopt.txt
  6. +1 −1 todo.txt
View
1 compiler/ast.nim
@@ -594,6 +594,7 @@ type
TLib* = object of lists.TListEntry # also misused for headers!
kind*: TLibKind
generated*: bool # needed for the backends:
+ isOverriden*: bool
name*: PRope
path*: PNode # can be a string literal!
View
7 compiler/commands.nim
@@ -212,6 +212,11 @@ proc track(arg: string, info: TLineInfo) =
LocalError(info, errInvalidNumber, a[2])
msgs.addCheckpoint(newLineInfo(a[0], line, column))
+proc dynlibOverride(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
+ if pass in {passCmd2, passPP}:
+ expectArg(switch, arg, pass, info)
+ options.inclDynlibOverride(arg)
+
proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
var
theOS: TSystemOS
@@ -480,6 +485,8 @@ proc processSwitch(switch, arg: string, pass: TCmdlinePass, info: TLineInfo) =
of "listfullpaths":
expectNoArg(switch, arg, pass, info)
gListFullPaths = true
+ of "dynliboverride":
+ dynlibOverride(switch, arg, pass, info)
else:
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
else: InvalidCmdLineOption(pass, switch, info)
View
15 compiler/options.nim
@@ -124,6 +124,7 @@ const
# additional configuration variables:
var
gConfigVars* = newStringTable(modeStyleInsensitive)
+ gDllOverrides = newStringtable(modeCaseInsensitive)
libpath* = ""
gProjectName* = "" # holds a name like 'nimrod'
gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/
@@ -256,6 +257,20 @@ proc libCandidates*(s: string, dest: var seq[string]) =
else:
add(dest, s)
+proc canonDynlibName(s: string): string =
+ let start = if s.startsWith("lib"): 3 else: 0
+ let ende = strutils.find(s, {'(', ')', '.'})
+ if ende >= 0:
+ result = s.substr(start, ende-1)
+ else:
+ result = s.substr(start)
+
+proc inclDynlibOverride*(lib: string) =
+ gDllOverrides[lib.canonDynlibName] = "true"
+
+proc isDynlibOverride*(lib: string): bool =
+ result = gDllOverrides.hasKey(lib.canonDynlibName)
+
proc binaryStrSearch*(x: openarray[string], y: string): int =
var a = 0
var b = len(x) - 1
View
7 compiler/pragmas.nim
@@ -202,6 +202,8 @@ proc getLib(c: PContext, kind: TLibKind, path: PNode): PLib =
result = newLib(kind)
result.path = path
Append(c.libs, result)
+ if path.kind in {nkStrLit..nkTripleStrLit}:
+ result.isOverriden = options.isDynLibOverride(path.strVal)
proc expectDynlibNode(c: PContext, n: PNode): PNode =
if n.kind != nkExprColonExpr:
@@ -225,8 +227,9 @@ proc processDynLib(c: PContext, n: PNode, sym: PSym) =
else:
if n.kind == nkExprColonExpr:
var lib = getLib(c, libDynamic, expectDynlibNode(c, n))
- addToLib(lib, sym)
- incl(sym.loc.flags, lfDynamicLib)
+ if not lib.isOverriden:
+ addToLib(lib, sym)
+ incl(sym.loc.flags, lfDynamicLib)
else:
incl(sym.loc.flags, lfExportLib)
# since we'll be loading the dynlib symbols dynamically, we must use
View
5 doc/advopt.txt
@@ -70,6 +70,11 @@ Advanced options:
--putenv:key=value set an environment variable
--babelPath:PATH add a path for Babel support
--excludePath:PATH exclude a path from the list of search paths
+ --dynlibOverride:SYMBOL marks SYMBOL so that dynlib:SYMBOL
+ has no effect and can be statically linked instead;
+ symbol matching is fuzzy so
+ that --dynlibOverride:lua matches
+ dynlib: "liblua.so.3"
--listCmd list the commands used to execute external programs
--parallelBuild=0|1|... perform a parallel build
value = number of processors (0 for auto-detect)
View
2 todo.txt
@@ -1,7 +1,6 @@
version 0.9.2
=============
-- a project wide override option for 'dynlib'
- FFI:
* test libffi on windows
* test: times.format with the FFI
@@ -29,6 +28,7 @@ Bugs
version 0.9.4
=============
+- ``try`` as an expression
- provide tool/API to track leaks/object counts
- hybrid GC
- use big blocks in the allocator

0 comments on commit 94becd0

Please sign in to comment.
Something went wrong with that request. Please try again.