Per-file or per-module compile flags

⚓ rust    📅 2025-05-13    👤 surdeus    👁️ 3      

surdeus

I am currently writing a little operating system kernel (for now only targetting x86(-64)) as a hobby, and to learn more about that kind of low-level programming. Up to now, I successfully used a "regular osdev" rust setup, with a custom target with all the juicy x86 vectorized ISA extensions disabled. Still, I felt that I still wanted to try to enable these features as an experiment (even though it adds some overhead to context-switches due to a bigger XSAVE region to copy, blah blah blah).
The problem is : I can't use these extensions without enabling them beforehand (by writing the right bits to the appropriate control registers), so I can't just compile my whole kernel with them enabled, with the risk of having the compiler use vectorized instructions where they still were not enabled.

So here is my question : is this possible to compile different files / modules from the same crate with different flags ? Since this is something feasible in C/C++, I think it would be a nice feature to add in the future, if it's not already the case.
Otherwise I suppose I should separate the init code and make it another crate of my project ?

I was also hoping that since #[target_feature(enable = ...)] exists, the opposite #[target_feature(disable = ...)] would also exist, but it's apparently not a thing for now.

EDIT : To clarify a bit, my initial goal was to compile initialization code (i.e. post bootloader code) without vectorized instructions enabled, and the rest of the kernel with them enabled

2 posts - 2 participants

Read full topic

🏷️ rust_feed