mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 07:21:19 +00:00
define nimVersion automatically and avoid needing -d:nimVersion140 (#18726)
* define `nimVersion` and avoid needing -d:nimVersion140 * fix changelog
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
# v1.8.x - yyyy-mm-dd
|
||||
|
||||
|
||||
|
||||
## Changes affecting backward compatibility
|
||||
|
||||
|
||||
@@ -16,6 +15,8 @@
|
||||
|
||||
## Compiler changes
|
||||
|
||||
- `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`,
|
||||
without requiring `-d:nimVersion140` which is now a noop.
|
||||
|
||||
|
||||
## Tool changes
|
||||
|
||||
@@ -656,7 +656,7 @@ type
|
||||
mUnaryPlusI, mBitnotI,
|
||||
mUnaryPlusF64, mUnaryMinusF64,
|
||||
mCharToStr, mBoolToStr,
|
||||
mIntToStr, mInt64ToStr, mFloatToStr, # for -d:nimVersion140
|
||||
mIntToStr, mInt64ToStr, mFloatToStr, # for compiling nimStdlibVersion < 1.5.1 (not bootstrapping)
|
||||
mCStrToStr,
|
||||
mStrToStr, mEnumToStr,
|
||||
mAnd, mOr,
|
||||
|
||||
@@ -894,7 +894,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
|
||||
let discIndex = rdSetElemLoc(p.config, v, u.t)
|
||||
if optTinyRtti in p.config.globalOptions:
|
||||
# not sure how to use `genEnumToStr` here
|
||||
if p.config.isDefined("nimVersion140"):
|
||||
if p.config.getStdlibVersion < (1,5,1):
|
||||
const code = "{ #raiseFieldError($1); $2} $n"
|
||||
linefmt(p, cpsStmts, code, [strLit, raiseInstr(p)])
|
||||
else:
|
||||
@@ -905,7 +905,7 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
|
||||
let first = p.config.firstOrd(disc.sym.typ)
|
||||
let firstLit = int64Literal(cast[int](first))
|
||||
let discName = genTypeInfo(p.config, p.module, disc.sym.typ, e.info)
|
||||
if p.config.isDefined("nimVersion140"):
|
||||
if p.config.getStdlibVersion < (1,5,1):
|
||||
const code = "{ #raiseFieldError($1); $2} $n"
|
||||
linefmt(p, cpsStmts, code, [strLit, raiseInstr(p)])
|
||||
else:
|
||||
|
||||
@@ -165,6 +165,7 @@ const
|
||||
cmdCtags, cmdBuildindex}
|
||||
|
||||
type
|
||||
NimVer* = tuple[major: int, minor: int, patch: int]
|
||||
TStringSeq* = seq[string]
|
||||
TGCMode* = enum # the selected GC
|
||||
gcUnselected = "unselected"
|
||||
@@ -346,6 +347,7 @@ type
|
||||
outDir*: AbsoluteDir
|
||||
jsonBuildFile*: AbsoluteFile
|
||||
prefixDir*, libpath*, nimcacheDir*: AbsoluteDir
|
||||
nimStdlibVersion*: NimVer
|
||||
dllOverrides, moduleOverrides*, cfileSpecificOptions*: StringTableRef
|
||||
projectName*: string # holds a name like 'nim'
|
||||
projectPath*: AbsoluteDir # holds a path like /home/alice/projects/nim/compiler/
|
||||
@@ -389,6 +391,16 @@ type
|
||||
cppCustomNamespace*: string
|
||||
vmProfileData*: ProfileData
|
||||
|
||||
proc parseNimVersion*(a: string): NimVer =
|
||||
# could be moved somewhere reusable
|
||||
if a.len > 0:
|
||||
let b = a.split(".")
|
||||
assert b.len == 3, a
|
||||
template fn(i) = result[i] = b[i].parseInt # could be optimized if needed
|
||||
fn(0)
|
||||
fn(1)
|
||||
fn(2)
|
||||
|
||||
proc assignIfDefault*[T](result: var T, val: T, def = default(T)) =
|
||||
## if `result` was already assigned to a value (that wasn't `def`), this is a noop.
|
||||
if result == def: result = val
|
||||
@@ -560,6 +572,12 @@ proc newPartialConfigRef*(): ConfigRef =
|
||||
proc cppDefine*(c: ConfigRef; define: string) =
|
||||
c.cppDefines.incl define
|
||||
|
||||
proc getStdlibVersion*(conf: ConfigRef): NimVer =
|
||||
if conf.nimStdlibVersion == (0,0,0):
|
||||
let s = conf.symbols.getOrDefault("nimVersion", "")
|
||||
conf.nimStdlibVersion = s.parseNimVersion
|
||||
result = conf.nimStdlibVersion
|
||||
|
||||
proc isDefined*(conf: ConfigRef; symbol: string): bool =
|
||||
if conf.symbols.hasKey(symbol):
|
||||
result = true
|
||||
|
||||
@@ -14,3 +14,5 @@ when defined(nimStrictMode):
|
||||
# switch("hint", "ConvFromXtoItselfNotNeeded")
|
||||
switch("hintAsError", "ConvFromXtoItselfNotNeeded")
|
||||
# future work: XDeclaredButNotUsed
|
||||
|
||||
switch("define", "nimVersion:" & NimVersion)
|
||||
|
||||
Reference in New Issue
Block a user