Skip to content

Move build flags to project-side nim.cfg and support more micros - #4

Open
dwhall wants to merge 3 commits into
markspanbroek:mainfrom
dwhall:dwhBuildFlags_2
Open

Move build flags to project-side nim.cfg and support more micros#4
dwhall wants to merge 3 commits into
markspanbroek:mainfrom
dwhall:dwhBuildFlags_2

Conversation

@dwhall

@dwhall dwhall commented Aug 31, 2024

Copy link
Copy Markdown

Previously, the nim compiler build flags were in the Python script. Since command-line settings prevent the use of any config file settings, this tool would prevent a user's build configuration. We should avoid this.

This commit moves the build flags to a new nim.cfg file that is copied to the user's project folder if one does not exist. This allows the user to change the build settings as needed. Two build flags, path and cpu, must be dynamically written into the config file because they come from the platformio environment variables in the Python script.

I added the "opt:size" build flag to nim.cfg.

I also added a support for more microcontroller families. A lookup table is used to convert the $PIOPLATFORM variable to the CPU type used by the Nim compiler. The result is put in the "cpu" build flag in the config file.

dwhall added 2 commits August 31, 2024 16:26
Previously, the nim compiler build flags were in the Python script.
Since command-line settings prevent the use of any config file settings,
this tool would overwrite a user's build configuration.  We should avoid this.

This commit moves the build flags to a new nim.cfg file that
is copied to the user's project folder if one does not exist.
This allows the user to change the build settings as needed.
Two build flags, path and cpu, must be dynamically written into the config file
because they come from the platformio values in the Python script.

I added the "opt:size" build flag to nim.cfg.

I also added a support for more microcontroller families.
A lookup table is used to convert the $PIOPLATFORM
variable to the CPU type used by the Nim compiler.
The result is put in the "cpu" build flag in the config file.
Previously, the nim compiler build flags were in the Python script.
Since command-line settings prevent the use of any config file settings,
this tool would overwrite a user's build configuration.  We should avoid this.

This commit moves the build flags to a new nim.cfg file that
is copied to the user's project folder if one does not exist.
This allows the user to change the build settings as needed.
Two build flags, path and cpu, must be dynamically written into the config file
because they come from the platformio values in the Python script.

I added the "opt:size" build flag to nim.cfg.

I also added a support for more microcontroller families.
A lookup table is used to convert the $PIOPLATFORM
variable to the CPU type used by the Nim compiler.
The result is put in the "cpu" build flag in the config file.
@dwhall

dwhall commented Sep 2, 2024

Copy link
Copy Markdown
Author

Hmmm. . . I have 2 projects that will build using this commit (with a nimbase from v2.0.0) and a couple other projects that won't build. The error I'm getting comes after the main.nim is build and it says, "Error: Nothing to build. Please put your source code files to the 'C:\Users....\proj\main\src' folder"
The success/failure seems to depend on the Platformio platform and framework selected by the project. I'll work on making this more reliable.

@markspanbroek

Copy link
Copy Markdown
Owner

Thank you for this! I unfortunately have a very busy week, so I won't be able to give a proper review and merge it until next week.

The error I'm getting comes after the main.nim is build and it says, "Error: Nothing to build. Please put your source code files to the 'C:\Users....\proj\main\src' folder"

This might be caused by the change to the nimcache parameter. Previously it was a path that was calculated in python to be relative to the project source dir. Now it's in nim.cfg as "src/nimcache". I'm not sure how this is interpreted by the nim compiler, but if it's interpreted as relative to the working directory then it might matter from which directory you're invoking the command to build.

@dwhall

dwhall commented Sep 3, 2024 via email

Copy link
Copy Markdown
Author

Previously, the nim compiler build flags were in the Python script.
Since command-line settings prevent the use of any config file settings,
this tool would override a user's build configuration.  We should avoid this.

This commit moves the build flags to a new nim.cfg file that
is copied to the user's project folder if one does not exist.
This allows the user to change the build settings as needed.
Three build flags, path, cpu and nimcache, must be programmatically
appended into the config file because parts of the value come from
the platformio environment values in the Python script.

I added the "opt:size" build flag to nim.cfg.

I also added support for more microcontroller families.
A lookup table is used to convert the $PIOPLATFORM
variable to the CPU type used by the Nim compiler.
The result is put in the "cpu" build flag in the config file.
@rknell

rknell commented Sep 7, 2024

Copy link
Copy Markdown

just a small gripe - perhaps we could store the nimcache in a ./build folder instead of next to the source? I'm not super familiar with nim coming from other languages, but it feels like im adding a lot of "junk" into where I keep the source code.

@dwhall

dwhall commented Sep 7, 2024

Copy link
Copy Markdown
Author

@rknell , I'll see what I can do, but I believe the cache is put at that location so the intermediate .c files can be found by PlatformIO.

@dwhall

dwhall commented Sep 7, 2024

Copy link
Copy Markdown
Author

@rknell , I believe I've found a hint that will let me do what you're asking for. I would like to put that change into a separate PR, though; just to keep things straight. Even though it may be "backtracking" on what happens to the nimcache path.

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.

3 participants