Currently, you cannot define a const or static value based on a function call. That requires the const functions feature to be completed.
That being said...
but I want to avoid runtime cost
tl;dr There is no runtime cost here, this is fine.
To avoid runtime cost, you should first ensure that you have runtime cost. To check, I used this code:
#[inline(never)]
fn bitsint() -> usize {
if ((isize::max_value() >> 15) >> 15) >= 1 {
12345
} else {
67890
}
}
fn main() {
println!("{}", bitsint());
}
I switched the values to make them easier to find in the assembly. The generated assembly does not have a function bitsint, even though I asked for it to not be inlined. It's hard to stop an optimizing compiler!
In the rest of the assembly, the value 67890 does not even occur, even though 12345 does.
An alternate solution may be to use conditional compilation. As an untested example:
#[cfg(target_pointer_width = "64")]
const LUAI_BITSINT: usize = 32;
#[cfg(not(target_pointer_width = "64"))]
const LUAI_BITSINT: usize = 16;
You could also use a build script to generate Rust code based on whatever conditions you want. This would create a constant that you could then include! into your code.