Does anyone have any examples of using nimble for more advanced build configurations?
Things I would like to do:
- Centralize generic build functionality into a github repo. Then, add that repo as a build tool dependency and import modules from it.
- It doesn't look like nimble has a concept of a build tool dependency, which seems to be the hurdle here
- List all .nim files in the test directory, compile and execute them.
- Nimble uses nimscript, which doesn't appear to have access to the os module, so I can't list out files. I could likely achieve this by calling exec "find ... | xargs nim c -r", but at that point I might as well just spin up a Makefile.
- Compile my public nim files to make sure they are all syntactically correct.
- Again, the hurdle appears to be identifying the files
- Extract code from my README and compile it
- Requires reading files, which requires the os module
- Model dependencies between targets
Also, when I run nimble build, nimble complains that there is "Nothing to build. Did you specify a module to build using the bin key in your .nimble file?". Can this be suppressed? I'm building libraries, so there are no bins. And it is forcing the exit code to be 1 instead of 0.
- Listing files in your nimble config doesn't use the os module, it uses the functions from the nimscript module directly
- Overriding the nimble build exit code isn't possible currently
Things I can't do:
- It doesn't look like a build tool dependency is possible. The build script needs to be executed so that the dependency list can be generated. Which is a chicken/egg problem.
- It doesn't look like I can read a file from nimscript? Is that correct?
- Modelling dependencies doesn't work. I can live without this.
Talking to myself, here. But what the heck.
It doesn't look like I can read a file from nimscript? Is that correct?
This is not correct. readFile and writeFile both work. lines, however, did not, which was the source of my confusion.
But it does leave me with one final problem: How do I abstract out my build scripts so they are usable from multiple packages?
Compile my public nim files to make sure they are all syntactically correct. Again, the hurdle appears to be identifying the files.
If by "public nim files" you mean files exposed for import by other packages, nimble seems to have a rule for this: put all non-public files in a source directory named private.
Model dependencies between targets
It isn't as dynamic as make's, but if it counts as "target dependency modeling" for you, you can use this:
before test: exec "nimble buildTests"
after is also available.
Extract code from my README and compile it
This could be done in a source file instead of a nims/nimble script by statically reading the README, extracting the source code snippets and building an AST from them via macro. After all, with regular source files, we make the compiler suck them in with import statements and don't piece them together in the build script.