Runtime initializaion of parametric type in package from input

Hi,

I have a package, where I want to define MyStaticVectorType type, as an alias to SVector{MEM_SIZE,Int} (from StaticArrays.jl).

Where MEM_SIZE is loaded from environment variable when the program runs, so it’s available before I call import MyPackage but after the package is precompiled/built.

To load a constant from environment variable, I created this macro:

macro const_from_env(const_name::Symbol, const_type::Symbol, default_value)
    esc(quote
        const $(const_name) = parse($(const_type), get(ENV, $("$const_name"), $("$default_value")))
        export $(const_name)
    end)
end

It works like this:

@const_from_env MEM_SIZE Int 16

So it would load from ENV["MEM_SIZE"] with a default value of 16.
If I run MEM_SIZE=4 julia

However, sometimes it gets stuck on the default value during package compilation.

Question is how to make it read the value (and define types) from current environment?

In other words, anything that depends on this parameter should not be procompiled and cached, but rather be evaluated when the package is imported.

Hope the question is clear, thanks in advance for any help!