Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[Feature] access compile time environment variables

Open b1ek opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. see #431

Describe the solution you'd like i think that we should add rust-like compile time macros, like env!() in this case which should enable the user to access compile time environment variables.

for the env!() macro, i suggest the following syntax:

fun env(variable: Text, default: Text): Text {
    // returns the specified variable if it exists, and default if it is set and the env variable is not available.
    // if default value is not set and variable is not available, it will throw a compile time error
}

which should be used like this:

const compile_commit = env!("COMPILE_COMMIT", "unknown");

which should be compiled to something like this (assuming COMPILE_COMMIT is set to a8c3083f:

declare -r compile_commit = "a8c3083f"

Describe alternatives you've considered https://github.com/amber-lang/amber/issues/431#issuecomment-2323256429

b1ek avatar Sep 01 '24 09:09 b1ek

IF those are compiler variables I think that env can be confusing with the env functions we have in stdlib. Maybe compiler_env is better.

Mte90 avatar Sep 02 '24 08:09 Mte90

IF those are compiler variables I think that env can be confusing with the env functions we have in stdlib. Maybe compiler_env is better.

yeah, i think that would work too. i suggested env!() because it is the same that rust has

b1ek avatar Sep 03 '24 01:09 b1ek