Skip to content

add srcDir variable to nim.cfg #24919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open

Conversation

Graveflo
Copy link
Contributor

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:

# config.nims
import os
let srcDir = currentSourcePath.parentDir()
switch("define", &"ProjPath:\"{srcDir}\"")

with this change just needs:

# nim.cfg
d %= "ProjPath=$srcDir"

@@ -223,6 +223,7 @@ proc readConfigFile*(filename: AbsoluteFile; cache: IdentCache;
stream = llStreamOpen(filename, fmRead)
if stream != nil:
openLexer(L, filename, stream, cache, config)
setConfigVar(config, "srcDir", parentDir(filename.string))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the feature but this seems offplace. Shouldn't it be done somewhere else in the compiler?

Copy link
Contributor Author

@Graveflo Graveflo May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into it again and it seems the path is determined in loadConfigs which calls readConfigFile (current placement of the change) and then it's promptly handed off to the machinery of while tok.tokType != tkEof: parseAssignment ... where the config file is processed. I don't see where else this could go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants