reggae
reggae copied to clipboard
How to use environment variables/runtime reggaefiles
If I try to get an environment variable to use in my reggaefile, by using std.process.environment.get
, I can't build it because the source for getenv is not available at compile-time. This could be remedied by providing some way to process reggae files without CTFE, which I'm not sure reggae currently supports, or provide some other way to access those env vars at compile-time. What do you suggest?
Either way, this project would really benefit from some examples. The written docs and unit tests cover many of the features, but nothing shows how to do things like some non-trivial examples.
I'm assuming you're trying to use std.process.environment
at file scope? "Simply" move the usage to inside a function. At the end all the compile-time trickery does is generate a getBuild
(can't remember the exact name now) function that returns the build description at runtime. It can always be written by hand, and in cases like this, has to be. Instead of:
mixin build!(foo, bar, baz);
Do:
Build getBuild() {
// you can use std.process.environment here
return Build(foo, baz, baz);
}
You may have to change some enum foo = Target(...)
to auto foo = Target(...)
if any of them needs runtime information, but other than that, that should be it.
I'll see what I can do about adding examples. The problem there is ensuring they all build correctly as well.
I tried what you suggested but get a bunch of template instantiation errors, even for stuff that doesn't rely on environment variables, such as objectFiles!
. I see that you don't use any of your template functions for your runtime reggae file for Phobos, I guess they can't be used at all with the runtime build description?
Phobos is... different. Big and complicated, also dependent on runtime values like environment variables. There shouldn't be any template instantiation errors, is it possible to show me what you wrote?