@@ -32,8 +32,8 @@ SUPPORTED_T1_PLATFORM_TRIPLES = {
3232 "x86_64-pc-windows-msvc" : _support (std = True , host_tools = True ),
3333 "x86_64-unknown-linux-gnu" : _support (std = True , host_tools = True ),
3434 "x86_64-unknown-nixos-gnu" : _support (std = True , host_tools = True ), # Same as `x86_64-unknown-linux-gnu` but with `@platforms//os:nixos`.
35- # N.B. These "alternative" envs are not supported, as bazel cannot distinguish between them
36- # and others using existing @platforms// config_values
35+ # N.B. These windows-gnu "alternative" envs are not supported, as bazel cannot
36+ # distinguish between MSVC and MinGW using existing @platforms// config_values.
3737 #
3838 #"i686-pc-windows-gnu",
3939 #"x86_64-pc-windows-gnu",
@@ -48,18 +48,23 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
4848 "aarch64-linux-android" : _support (std = True , host_tools = False ),
4949 "aarch64-pc-windows-msvc" : _support (std = True , host_tools = True ),
5050 "aarch64-unknown-fuchsia" : _support (std = True , host_tools = False ),
51+ "aarch64-unknown-linux-musl" : _support (std = True , host_tools = True ),
5152 "aarch64-unknown-uefi" : _support (std = True , host_tools = False ),
5253 "arm-unknown-linux-gnueabi" : _support (std = True , host_tools = True ),
5354 "arm-unknown-linux-musleabi" : _support (std = True , host_tools = True ),
5455 "armv7-linux-androideabi" : _support (std = True , host_tools = False ),
5556 "armv7-unknown-linux-gnueabi" : _support (std = True , host_tools = True ),
5657 "i686-linux-android" : _support (std = True , host_tools = False ),
5758 "i686-unknown-freebsd" : _support (std = True , host_tools = False ),
59+ "i686-unknown-linux-musl" : _support (std = True , host_tools = True ),
5860 "powerpc-unknown-linux-gnu" : _support (std = True , host_tools = True ),
61+ "powerpc-unknown-linux-musl" : _support (std = True , host_tools = True ),
5962 "riscv32imc-unknown-none-elf" : _support (std = True , host_tools = False ),
6063 "riscv64gc-unknown-linux-gnu" : _support (std = True , host_tools = False ),
64+ "riscv64gc-unknown-linux-musl" : _support (std = True , host_tools = False ),
6165 "riscv64gc-unknown-none-elf" : _support (std = True , host_tools = False ),
6266 "s390x-unknown-linux-gnu" : _support (std = True , host_tools = True ),
67+ "s390x-unknown-linux-musl" : _support (std = True , host_tools = True ),
6368 "thumbv6m-none-eabi" : _support (std = True , host_tools = False ),
6469 "thumbv7em-none-eabi" : _support (std = True , host_tools = False ),
6570 "thumbv7em-none-eabihf" : _support (std = True , host_tools = False ),
@@ -74,6 +79,7 @@ SUPPORTED_T2_PLATFORM_TRIPLES = {
7479 "x86_64-linux-android" : _support (std = True , host_tools = False ),
7580 "x86_64-unknown-freebsd" : _support (std = True , host_tools = True ),
7681 "x86_64-unknown-fuchsia" : _support (std = True , host_tools = False ),
82+ "x86_64-unknown-linux-musl" : _support (std = True , host_tools = True ),
7783 "x86_64-unknown-none" : _support (std = True , host_tools = False ),
7884 "x86_64-unknown-uefi" : _support (std = True , host_tools = False ),
7985}
@@ -268,8 +274,10 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = {
268274 "fuchsia" : ["-lzircon" , "-lfdio" ],
269275 "illumos" : ["-lsocket" , "-lposix4" , "-lpthread" , "-lresolv" , "-lnsl" , "-lumem" ],
270276 "ios" : ["-lSystem" , "-lobjc" , "-Wl,-framework,Security" , "-Wl,-framework,Foundation" , "-lresolv" ],
271- # TODO: This ignores musl. Longer term what does Bazel think about musl?
272- "linux" : ["-ldl" , "-lpthread" ],
277+ "linux" : {
278+ None : ["-ldl" , "-lpthread" ],
279+ "musl" : [],
280+ },
273281 "macos" : ["-lSystem" , "-lresolv" ],
274282 "nacl" : [],
275283 "netbsd" : ["-lpthread" , "-lrt" ],
@@ -340,20 +348,18 @@ def abi_to_constraints(abi, *, arch = None, system = None):
340348
341349 all_abi_constraints = []
342350
343- # add constraints for MUSL static compilation and linking
344- # to separate the MUSL from the non-MUSL toolchain on x86_64
345- # if abi == "musl" and system == "linux" and arch == "x86_64":
346- # all_abi_constraints.append("//rust/platform/constraints:musl_on")
347-
348351 # add constraints for iOS + watchOS simulator and device triples
349352 if system in ["ios" , "watchos" ]:
350353 if arch == "x86_64" or abi == "sim" :
351354 all_abi_constraints .append ("@build_bazel_apple_support//constraints:simulator" )
352355 else :
353356 all_abi_constraints .append ("@build_bazel_apple_support//constraints:device" )
354357
355- # TODO(bazelbuild/platforms#38): Implement when C++ toolchain is more mature and we
356- # figure out how they're doing this
358+ if abi :
359+ if abi .startswith ("musl" ):
360+ all_abi_constraints .append ("@platforms_contrib//libc:musl" )
361+ elif abi .startswith ("gnu" ):
362+ all_abi_constraints .append ("@platforms_contrib//libc:glibc" )
357363 return all_abi_constraints
358364
359365def triple_to_system (target_triple ):
@@ -410,8 +416,15 @@ def system_to_staticlib_ext(system):
410416def system_to_binary_ext (system ):
411417 return _SYSTEM_TO_BINARY_EXT [system ]
412418
413- def system_to_stdlib_linkflags (system ):
414- return _SYSTEM_TO_STDLIB_LINKFLAGS [system ]
419+ def system_to_stdlib_linkflags (system , abi = None ):
420+ flags = _SYSTEM_TO_STDLIB_LINKFLAGS [system ]
421+ if type (flags ) == "list" :
422+ return flags
423+ if abi :
424+ for prefix , abi_flags in flags .items ():
425+ if prefix and abi .startswith (prefix ):
426+ return abi_flags
427+ return flags .get (None , [])
415428
416429def triple_to_constraint_set (target_triple ):
417430 """Returns a set of constraints for a given platform triple
0 commit comments