Open ssrimindset opened 2 years ago
This is intentionally not supported because Zig has multiple linker backends and multiple compiler backends - idea being that you can switch from LLVM to a different one seamlessly. Setting this global state wreaks havoc on this abstraction.
However, I recognize that when using LLVM, some advanced use cases would benefit from this ability. So the trick is to balance the API, making it difficult enough to use that nobody stumbles upon it, but still possible to use when the person knows what they are doing.
One particular use case where I was looking forward to this possibility (just theoretically, not that far with zig usage yet) is floating point fast math. The standard fast math option of clang is often too aggressive as, in my and some of my colleagues' experience, it may quite often cause lots of precision loss in the computations. However, fast-math in clang has more granular control, and IIRC it's just one or two granular options which are causing trouble. The majority of fast-math options are simply about ignoring boundary cases like INFs, NaNs and distinct signed zero, and do not affect computation precision. I'd assume it's the same in LLVM in general.
Not fully sure, how does Zig configure release options, but I assume it's the same fast-math as in clang, in which case more granular control could be highly desirable.
I might have missed something, but I also want to pass some linker flags to zig, and I do not know how. I am building a plugin with zig. It will be manually loaded in a C application, that makes some functions (i.e. symbols) available (the API of the plugin). On macOS (unlike on linux) by default all symbols must be resolved, so when building the shared library it complains about the undefined symbols. To avoid that I should pass either -undefined dynamic_lookup or -Wl,-U,symbol_name for all symbols of the API. but I do not find how...
it seems that for my use case a solution has been added to the linker, see https://github.com/ziglang/zig/issues/3085 , also -Wl,-undefined,dynamic_lookup should work as described in https://github.com/ziglang/zig/issues/8180 and I still miss how to pass it using build.zig, but that is not exactly this issue anymore
also that is solved, lib.linker_allow_shlib_undefined = true
, not all options of the library objects are available at construction time in Build.SharedLibraryOptions...(thanks !no ones uncle)
I think it will be pretty useful to be able to pass flags to clang/llvm itsef. I use them quite often in low level scenarious. For it to be possilbe, all it needs is to add another function which will pass them to main.zig clang_argv
If it's intentional not to do so, can you explain why?