@@ -124,8 +124,37 @@ def output_filename(cratename: str, emit: Emit, buildparams: BuildParams, extra:
124
124
# Rule type - 'binary' also covers 'test'
125
125
RuleType = enum ("binary" , "library" )
126
126
127
- # What language we're generating artifacts to be linked with
128
- LinkageLang = enum ("rust" , "c++" )
127
+ # Controls how we build our rust libraries, largely dependent on whether rustc
128
+ # or buck is driving the final linking and whether we are linking the artifact
129
+ # into other rust targets.
130
+ #
131
+ # Rust: In this mode, we build rust libraries as rlibs. This is the primary
132
+ # approach for building rust targets when the final link step is driven by
133
+ # rustc (e.g. rust_binary, rust_unittest, etc).
134
+ #
135
+ # Native: In this mode, we build rust libraries as staticlibs, where rustc
136
+ # will bundle all of this target's rust dependencies into a single library
137
+ # artifact. This approach is the most standardized way to build rust libraries
138
+ # for linkage in non-rust code.
139
+ #
140
+ # NOTE: This approach does not scale well. It's possible to end up with
141
+ # non-rust target A depending on two rust targets B and C, which can cause
142
+ # duplicate symbols if B and C share common rust dependencies.
143
+ #
144
+ # Native Unbundled: In this mode, we revert back to building as rlibs. This
145
+ # approach mitigates the duplicate symbol downside of the "Native" approach.
146
+ # However, this option is not formally supported by rustc, and depends on an
147
+ # implementation detail of rlibs (they're effectively .a archives and can be
148
+ # linked with other native code using the CXX linker).
149
+ #
150
+ # See https://github.com/rust-lang/rust/issues/73632 for more details on
151
+ # stabilizing this approach.
152
+
153
+ LinkageLang = enum (
154
+ "rust" ,
155
+ "native" ,
156
+ "native-unbundled" ,
157
+ )
129
158
130
159
_BINARY_SHARED = 0
131
160
_BINARY_PIE = 1
@@ -231,10 +260,15 @@ _INPUTS = {
231
260
("binary" , False , "static" , "shared" , "rust" ): _BINARY_NON_PIE ,
232
261
("binary" , False , "static" , "static" , "rust" ): _BINARY_NON_PIE ,
233
262
# Native linkable shared object
234
- ("library" , False , "shared" , "any" , "c++" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
235
- ("library" , False , "shared" , "shared" , "c++" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
236
- ("library" , False , "static" , "shared" , "c++" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
237
- ("library" , False , "static_pic" , "shared" , "c++" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
263
+ ("library" , False , "shared" , "any" , "native" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
264
+ ("library" , False , "shared" , "shared" , "native" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
265
+ ("library" , False , "static" , "shared" , "native" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
266
+ ("library" , False , "static_pic" , "shared" , "native" ): _NATIVE_LINKABLE_SHARED_OBJECT ,
267
+ # Native unbundled linkable shared object
268
+ ("library" , False , "shared" , "any" , "native-unbundled" ): _RUST_DYLIB_SHARED ,
269
+ ("library" , False , "shared" , "shared" , "native-unbundled" ): _RUST_DYLIB_SHARED ,
270
+ ("library" , False , "static" , "shared" , "native-unbundled" ): _RUST_DYLIB_SHARED ,
271
+ ("library" , False , "static_pic" , "shared" , "native-unbundled" ): _RUST_DYLIB_SHARED ,
238
272
# Rust dylib shared object
239
273
("library" , False , "shared" , "any" , "rust" ): _RUST_DYLIB_SHARED ,
240
274
("library" , False , "shared" , "shared" , "rust" ): _RUST_DYLIB_SHARED ,
@@ -258,12 +292,19 @@ _INPUTS = {
258
292
("library" , False , "static" , "any" , "rust" ): _RUST_STATIC_NON_PIC_LIBRARY ,
259
293
("library" , False , "static" , "static" , "rust" ): _RUST_STATIC_NON_PIC_LIBRARY ,
260
294
# Native linkable static_pic
261
- ("library" , False , "shared" , "static" , "c++ " ): _NATIVE_LINKABLE_STATIC_PIC ,
262
- ("library" , False , "static_pic" , "any" , "c++ " ): _NATIVE_LINKABLE_STATIC_PIC ,
263
- ("library" , False , "static_pic" , "static" , "c++ " ): _NATIVE_LINKABLE_STATIC_PIC ,
295
+ ("library" , False , "shared" , "static" , "native " ): _NATIVE_LINKABLE_STATIC_PIC ,
296
+ ("library" , False , "static_pic" , "any" , "native " ): _NATIVE_LINKABLE_STATIC_PIC ,
297
+ ("library" , False , "static_pic" , "static" , "native " ): _NATIVE_LINKABLE_STATIC_PIC ,
264
298
# Native linkable static non-pic
265
- ("library" , False , "static" , "any" , "c++" ): _NATIVE_LINKABLE_STATIC_NON_PIC ,
266
- ("library" , False , "static" , "static" , "c++" ): _NATIVE_LINKABLE_STATIC_NON_PIC ,
299
+ ("library" , False , "static" , "any" , "native" ): _NATIVE_LINKABLE_STATIC_NON_PIC ,
300
+ ("library" , False , "static" , "static" , "native" ): _NATIVE_LINKABLE_STATIC_NON_PIC ,
301
+ # Native Unbundled static_pic library
302
+ ("library" , False , "shared" , "static" , "native-unbundled" ): _RUST_STATIC_PIC_LIBRARY ,
303
+ ("library" , False , "static_pic" , "any" , "native-unbundled" ): _RUST_STATIC_PIC_LIBRARY ,
304
+ ("library" , False , "static_pic" , "static" , "native-unbundled" ): _RUST_STATIC_PIC_LIBRARY ,
305
+ # Native Unbundled static (non-pic) library
306
+ ("library" , False , "static" , "any" , "native-unbundled" ): _RUST_STATIC_NON_PIC_LIBRARY ,
307
+ ("library" , False , "static" , "static" , "native-unbundled" ): _RUST_STATIC_NON_PIC_LIBRARY ,
267
308
}
268
309
269
310
# Check types of _INPUTS, writing these out as types is too verbose, but let's make sure we don't have any typos.
0 commit comments