* fix #18578 * add tests * tiny * apply changes * typo * add removeStaticFile
This commit is contained in:
parent
22776c410a
commit
9cb5ab0108
3 changed files with 32 additions and 6 deletions
|
|
@ -665,9 +665,10 @@ proc addExternalFileToCompile*(conf: ConfigRef; filename: AbsoluteFile) =
|
||||||
addExternalFileToCompile(conf, c)
|
addExternalFileToCompile(conf, c)
|
||||||
|
|
||||||
proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
|
proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
|
||||||
objfiles: string, isDllBuild: bool): string =
|
objfiles: string, isDllBuild: bool, removeStaticFile: bool): string =
|
||||||
if optGenStaticLib in conf.globalOptions:
|
if optGenStaticLib in conf.globalOptions:
|
||||||
removeFile output # fixes: bug #16947
|
if removeStaticFile:
|
||||||
|
removeFile output # fixes: bug #16947
|
||||||
result = CC[conf.cCompiler].buildLib % ["libfile", quoteShell(output),
|
result = CC[conf.cCompiler].buildLib % ["libfile", quoteShell(output),
|
||||||
"objfiles", objfiles]
|
"objfiles", objfiles]
|
||||||
else:
|
else:
|
||||||
|
|
@ -750,8 +751,9 @@ proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
|
||||||
if optCDebug in conf.globalOptions and conf.cCompiler == ccVcc:
|
if optCDebug in conf.globalOptions and conf.cCompiler == ccVcc:
|
||||||
result.add " /Zi /FS /Od"
|
result.add " /Zi /FS /Od"
|
||||||
|
|
||||||
template getLinkCmd(conf: ConfigRef; output: AbsoluteFile, objfiles: string): string =
|
template getLinkCmd(conf: ConfigRef; output: AbsoluteFile, objfiles: string,
|
||||||
getLinkCmd(conf, output, objfiles, optGenDynLib in conf.globalOptions)
|
removeStaticFile = false): string =
|
||||||
|
getLinkCmd(conf, output, objfiles, optGenDynLib in conf.globalOptions, removeStaticFile)
|
||||||
|
|
||||||
template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body: untyped) =
|
template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body: untyped) =
|
||||||
try:
|
try:
|
||||||
|
|
@ -891,7 +893,7 @@ proc callCCompiler*(conf: ConfigRef) =
|
||||||
let objFile = conf.getObjFilePath(x)
|
let objFile = conf.getObjFilePath(x)
|
||||||
let buildDll = idx != mainFileIdx
|
let buildDll = idx != mainFileIdx
|
||||||
let linkTarget = conf.hcrLinkTargetName(objFile, not buildDll)
|
let linkTarget = conf.hcrLinkTargetName(objFile, not buildDll)
|
||||||
cmds.add(getLinkCmd(conf, linkTarget, objfiles & " " & quoteShell(objFile), buildDll))
|
cmds.add(getLinkCmd(conf, linkTarget, objfiles & " " & quoteShell(objFile), buildDll, removeStaticFile = true))
|
||||||
# try to remove all .pdb files for the current binary so they don't accumulate endlessly in the nimcache
|
# try to remove all .pdb files for the current binary so they don't accumulate endlessly in the nimcache
|
||||||
# for more info check the comment inside of getLinkCmd() where the /PDB:<filename> MSVC flag is used
|
# for more info check the comment inside of getLinkCmd() where the /PDB:<filename> MSVC flag is used
|
||||||
if isVSCompatible(conf):
|
if isVSCompatible(conf):
|
||||||
|
|
@ -914,7 +916,8 @@ proc callCCompiler*(conf: ConfigRef) =
|
||||||
objfiles.add(quoteShell(objFile))
|
objfiles.add(quoteShell(objFile))
|
||||||
let mainOutput = if optGenScript notin conf.globalOptions: conf.prepareToWriteOutput
|
let mainOutput = if optGenScript notin conf.globalOptions: conf.prepareToWriteOutput
|
||||||
else: AbsoluteFile(conf.projectName)
|
else: AbsoluteFile(conf.projectName)
|
||||||
linkCmd = getLinkCmd(conf, mainOutput, objfiles)
|
|
||||||
|
linkCmd = getLinkCmd(conf, mainOutput, objfiles, removeStaticFile = true)
|
||||||
extraCmds = getExtraCmds(conf, mainOutput)
|
extraCmds = getExtraCmds(conf, mainOutput)
|
||||||
if optCompileOnly notin conf.globalOptions:
|
if optCompileOnly notin conf.globalOptions:
|
||||||
const MaxCmdLen = when defined(windows): 8_000 else: 32_000
|
const MaxCmdLen = when defined(windows): 8_000 else: 32_000
|
||||||
|
|
|
||||||
1
tests/compiles/mstaticlib.nim
Normal file
1
tests/compiles/mstaticlib.nim
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
echo 1234
|
||||||
22
tests/compiles/tstaticlib.nim
Normal file
22
tests/compiles/tstaticlib.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import std/[os, osproc, strformat]
|
||||||
|
|
||||||
|
|
||||||
|
const dir = "tests/compiles"
|
||||||
|
const fileName = dir / "mstaticlib.nim"
|
||||||
|
const nim = getCurrentCompilerExe()
|
||||||
|
|
||||||
|
block: # bug #18578
|
||||||
|
const libName = dir / "tstaticlib1.a"
|
||||||
|
let (_, status) = execCmdEx(fmt"{nim} c -o:{libName} --app:staticlib {fileName}")
|
||||||
|
doAssert status == 0
|
||||||
|
doAssert fileExists(libName)
|
||||||
|
removeFile(libName)
|
||||||
|
|
||||||
|
block: # bug #16947
|
||||||
|
const libName = dir / "tstaticlib2.a"
|
||||||
|
writeFile(libName, "echo 124")
|
||||||
|
doAssert fileExists(libName)
|
||||||
|
let (_, status) = execCmdEx(fmt"{nim} c -o:{libName} --app:staticlib {fileName}")
|
||||||
|
doAssert status == 0
|
||||||
|
doAssert fileExists(libName)
|
||||||
|
removeFile(libName)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue