Implement `zig_shared_library` to generate shared objects or dynamic libraries
aherrmann opened this issue · comments
Replaces #16.
Bazel's builtin CC rules eventually opted to add a new cc_shared_library
rule because shared library use-cases often differ from static library use-cases. So, it seems like a good starting point to implement dynamic library support in a separate rule. If we determine in future that zig_library
should support both, then merging zig_shared_library
into zig_library
will likely be the easier migration path, than the other way around.
To not conflate this issue with #14, the first implementation should not attempt to generate or integrate with CcInfo
, yet. Instead, it should just generate a .so|.dylib|.dll
as a default output. Integration with the builtin C/C++ rules can be achieved as follows (sketch):
zig_shared_library(
name = "zig-lib",
...
)
cc_library(
name = "cc-lib",
srcs = [":zig-lib"],
)
Suggested implementation steps:
- Create an end-to-end test similar to the static library test.
- Add a new
zig_shared_library
rule (see here and here for reference). - Amend the common rule implementation to handle the shared library case (see here and here).
- Add a cross-platform outputs test similar to the static library test (add corresponding
//zig/tests/simple-shared-library
target similar to//zig/tests/simple-library
). - Handle all relevant target platforms in the implementation.
- Provide adequate rule documentation (see here for reference).
- Run
bazel run //util:gazelle
andbazel run //util:update
to update generated targets, files, and documentation.
Closed by #103