I am using Rust to target a baremetal system. My startup code is written in Assembly and is in crt0.S, it is shared between Rust, C and Assembly projects.
crt0.S contains:
#include "constants.h"
li a0, A_CONSTANT
When building crt0.S as part of a C program, the preprocessor runs and substitutes a value for A_CONSTANT.
This does not happen in Rust, but I can use bindgen then substitute the value in global_asm
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
global_asm!(include_str!("crt0.S"), A_CONSTANT = const A_CONSTANT);
However, I then need to write crt0.S like this, which won't compile in C/asm
li a0, {A_CONSTANT}
Is there some way I can write the line in crt0.S which will work for both?
How about moving your constants into some .inc file written in assembly like A_CONSTANT .equ 1234 and then include it using .include directive?
Then I won't be able to use the constants from C code. I also need them from code which does not link with the assembly.
gcc -Eorclang -E) before assembling it.