-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Support for compiler build variables #664
Comments
Go's approach is to allow overriding of string constants, provided they're defined using the |
When introducing this feature, we can also use it to replace the built-in constants |
After some thinking, my plan is as follows: We'll take the Go approach of overriding constants for the following reasons:
To make this work well, constants can only be overwritten if they are public and either a String, Int, or Bool. Variables are defined using If the constant is a string, the value is taken as-is and interpreted as a string. If the constant is an Int, we error if the value isn't a valid These variables are collected into a When generating object files, we hash the contents of The result of this setup is that build tags are used for conditional compilation, while build variables are used for build specific configuration, such as what paths to use for looking up certain files (e.g. |
Description
Projects may wish to use resources from configurable locations, such as a directory containing files to copy around. The locations may differ during development and production. For example, during development one may wish to use
./foo
, while in production one may wish to use/usr/share/bla/foo
.To allow for this, we should extend the compiler to support build variables. These variables are obtained at runtime (not compile time, so you can't do conditional compilation based on them), and only support
String
values. The variables would be obtained usingstd.env.build_variable
, returning anOption[String]
.One way we could introduce these variables is using
inko build --variable='KEY:VALUE'
, i.e.inko build --variable="DATABASE:/var/lib/bla"
. One question this brings is how to handle build variables for (nested) dependencies, as using regular names like this may introduce conflicts. One option there is to simply recommend users to not use variables for libraries and only for executables, as libraries don't really need them to begin with.An example of where this would be useful is Inko's own compiler: it needs to know where the standard library is located, and where the runtime library to link against is located. These paths are specified using build variables, allowing users to customize these if needed.
Related work
The text was updated successfully, but these errors were encountered: