-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: remove per-module targets #22285
Comments
Note for dynamic dispatch, if anybody else is wondering how this might work: |
What about executables with a mix of arm and thumb? I think this could be important for embedded development, or in my case, homebrew for the Nintendo DS. I haven't actually tried any code that does mix arm and thumb, so I'm not sure what the current behavior is, but intuitively I would think to just use different targets in different modules to switch between the two architectures. |
Real world use case: https://jonot.me/posts/zig-gba/#thumb-codearm-code |
Can this use case be covered by just having the Per-module target for this feels like overkill. |
That's a good suggestion for this use case. Another use case is #1018 |
Thumb/ARM is essentially the only valid use case I've really seen, and it feels like something that should be handled outside of this system. As suggested by Alex, a builtin (
I think I covered this in the original issue:
I'm up for having a language-level way to do this rather than requiring multiple CUs, but trying to achieve it with per-module targets feels like at best a local maximum. |
#18160 was responsible for expanding Zig modules to include lots of state, such as link libraries, C source files, and optimization mode. One such property which can now be set on a per-module basis is the target.
Clearly, targets with (for instance) different object formats cannot be combined into a single output executable; it is also unclear whether there is a sane way to combine, for instance, different CPU architectures in one executable. The real stated use case in #18160 for this feature is to allow modules to be compiled with different CPU feature sets.
Presumably, the idea here is that a piece of source code can be compiled N times with N different CPU feature sets, allowing a single binary to run correctly and optimally across a variety of CPU models. However, the problem with this is that Zig does not allow a single file to exist in multiple modules. As such, this use case immediately breaks down: you cannot compile the same code N times for different CPU feature sets using modules alone.
Meanwhile, modules having different targets introduces other complexities. Clearly, this is difficult to support in the compiler; indeed, it doesn't really work today at all. Additionally, it introduces the problem that the standard library either cannot be shared, or needs to be compiled for the "least feature set" of all targets. Aside from code bloat, non-sharing of the standard library leads to the same usability issues as the ability to have one file in multiple modules would; namely, that
std.ArrayListUnmanaged(u8)
from module A is not necessarily the same type asstd.ArrayListUnmanaged(u8)
from module B. This leads to another issue with modules having different targets: it is unclear how these modules are actually allowed to interact. Can datastructures be exchanged between them?Given that this feature fails to solve the problem it sets out to solve, and introduces many more issues and complexities along the way, I propose to remove this feature. The target should become a global option; for the build system, it should be set on
std.Build.Step.Compile
rather than onstd.Build.Module
.Notes
The text was updated successfully, but these errors were encountered: