From 42f1c3944cb184ad64dabc0449afb3b86b4fea61 Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Thu, 23 Oct 2025 03:05:05 -0400 Subject: [PATCH] add `srcDir` variable to nim.cfg (#24919) There might be a way to do this but I couldn't find anything about it. This is a very simple thing that goes a long way in certain situations. Trying to avoid needing to switch to nimscript just to get: ```nim # config.nims import os let srcDir = currentSourcePath.parentDir() switch("define", &"ProjPath:\"{srcDir}\"") ``` with this change just needs: ``` # nim.cfg d %= "ProjPath=$srcDir" ``` (cherry picked from commit 544c26c0b8c6ba32a8655f9718ebef8467aa6d27) --- compiler/nimconf.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 5417cd1e93..5d31dea57f 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -207,7 +207,6 @@ proc parseAssignment(L: var Lexer, tok: var Token; checkSymbol(L, tok) val.add($tok) confTok(L, tok, config, condStack) - config.currentConfigDir = parentDir(filename.string) if percent: processSwitch(s, strtabs.`%`(val, config.configVars, {useEnvironment, useEmpty}), passPP, info, config) @@ -249,6 +248,8 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef; idgen: setDefaultLibpath(conf) template readConfigFile(path) = let configPath = path + conf.currentConfigDir = configPath.splitFile.dir.string + setConfigVar(conf, "selfDir", conf.currentConfigDir) if readConfigFile(configPath, cache, conf): conf.configFiles.add(configPath)