From 6d510d99b248a4b6db7e6e299298cf78e9a783d7 Mon Sep 17 00:00:00 2001 From: Ashwin Kishin Banwari Date: Sun, 10 Nov 2024 02:26:56 -0800 Subject: [PATCH 1/2] works for my engine --- prelude/cxx/cxx_executable.bzl | 6 +++++- prelude/cxx/cxx_library.bzl | 3 +-- prelude/cxx/cxx_link_utility.bzl | 2 +- prelude/toolchains/cxx.bzl | 7 ++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/prelude/cxx/cxx_executable.bzl b/prelude/cxx/cxx_executable.bzl index cf639b8b2e326..d776a356279d2 100644 --- a/prelude/cxx/cxx_executable.bzl +++ b/prelude/cxx/cxx_executable.bzl @@ -227,7 +227,11 @@ def cxx_executable(ctx: AnalysisContext, impl_params: CxxRuleConstructorParams, inherited_preprocessor_infos, is_coverage_enabled_by_any_dep(ctx, preprocessor_deps), ) - compile_flavor = CxxCompileFlavor("pic") if link_strategy != LinkStrategy("static") else CxxCompileFlavor("default") + if link_strategy == LinkStrategy("static") or get_cxx_toolchain_info(ctx).pic_behavior != "supported": + compile_flavor = CxxCompileFlavor("default") + else: + compile_flavor = CxxCompileFlavor("pic") + cxx_outs = compile_cxx( ctx = ctx, src_compile_cmds = compile_cmd_output.src_compile_cmds, diff --git a/prelude/cxx/cxx_library.bzl b/prelude/cxx/cxx_library.bzl index 47466e50dbd5f..abe0d8b849f09 100644 --- a/prelude/cxx/cxx_library.bzl +++ b/prelude/cxx/cxx_library.bzl @@ -1379,8 +1379,7 @@ def _strip_objects(ctx: AnalysisContext, objects: list[Artifact]) -> list[Artifa cxx_toolchain_info = get_cxx_toolchain_info(ctx) # Stripping is not supported on Windows - linker_type = cxx_toolchain_info.linker_info.type - if linker_type == LinkerType("windows"): + if host_info().os.is_windows: return objects # Disable stripping if no `strip` binary was provided by the toolchain. diff --git a/prelude/cxx/cxx_link_utility.bzl b/prelude/cxx/cxx_link_utility.bzl index 6b357eed03864..18e1710cc945d 100644 --- a/prelude/cxx/cxx_link_utility.bzl +++ b/prelude/cxx/cxx_link_utility.bzl @@ -251,7 +251,7 @@ def executable_shared_lib_arguments( linker_type = cxx_toolchain.linker_info.type if len(shared_libs) > 0: - if linker_type == LinkerType("windows"): + if host_info().os.is_windows: shared_libs_symlink_tree = [ctx.actions.symlink_file( shlib.lib.output.basename, shlib.lib.output, diff --git a/prelude/toolchains/cxx.bzl b/prelude/toolchains/cxx.bzl index 93baa02425f83..08ac3e515fcd5 100644 --- a/prelude/toolchains/cxx.bzl +++ b/prelude/toolchains/cxx.bzl @@ -96,7 +96,6 @@ def _cxx_toolchain_from_cxx_tools_info(ctx: AnalysisContext, cxx_tools_info: Cxx additional_linker_flags = ["-fuse-ld=lld"] if os == "linux" and cxx_tools_info.linker != "g++" and cxx_tools_info.cxx_compiler != "g++" else [] if os == "windows": - linker_type = LinkerType("windows") binary_extension = "exe" object_file_extension = "obj" static_library_extension = "lib" @@ -113,10 +112,8 @@ def _cxx_toolchain_from_cxx_tools_info(ctx: AnalysisContext, cxx_tools_info: Cxx shared_library_versioned_name_format = "{}.so.{}" if os == "macos": - linker_type = LinkerType("darwin") pic_behavior = PicBehavior("always_enabled") else: - linker_type = LinkerType("gnu") pic_behavior = PicBehavior("supported") if cxx_tools_info.compiler_type == "clang": @@ -137,7 +134,7 @@ def _cxx_toolchain_from_cxx_tools_info(ctx: AnalysisContext, cxx_tools_info: Cxx archiver_supports_argfiles = archiver_supports_argfiles, generate_linker_maps = False, lto_mode = LtoMode("none"), - type = linker_type, + type = cxx_tools_info.linker_type, link_binaries_locally = True, link_libraries_locally = True, archive_objects_locally = True, @@ -156,7 +153,7 @@ def _cxx_toolchain_from_cxx_tools_info(ctx: AnalysisContext, cxx_tools_info: Cxx shared_library_versioned_name_format = shared_library_versioned_name_format, static_library_extension = static_library_extension, force_full_hybrid_if_capable = False, - is_pdb_generated = is_pdb_generated(linker_type, ctx.attrs.link_flags), + is_pdb_generated = is_pdb_generated(cxx_tools_info.linker_type, ctx.attrs.link_flags), link_ordering = ctx.attrs.link_ordering, ), bolt_enabled = False, From 26dca941111270d6348a997ec8fd6e101ced8306 Mon Sep 17 00:00:00 2001 From: Ashwin Kishin Banwari Date: Sun, 10 Nov 2024 20:50:22 -0800 Subject: [PATCH 2/2] update clang_tools default archiver name --- prelude/toolchains/cxx/clang/tools.bzl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/prelude/toolchains/cxx/clang/tools.bzl b/prelude/toolchains/cxx/clang/tools.bzl index 05f4a6a1b0db0..50447cdf2c015 100644 --- a/prelude/toolchains/cxx/clang/tools.bzl +++ b/prelude/toolchains/cxx/clang/tools.bzl @@ -9,6 +9,10 @@ load("@prelude//cxx:cxx_toolchain_types.bzl", "LinkerType") load("@prelude//toolchains:cxx.bzl", "CxxToolsInfo") def _path_clang_tools_impl(_ctx) -> list[Provider]: + if host_info().os.is_windows: + archiver = "llvm-ar" + else: + archiver = "ar" return [ DefaultInfo(), CxxToolsInfo( @@ -19,7 +23,7 @@ def _path_clang_tools_impl(_ctx) -> list[Provider]: asm_compiler_type = "clang", rc_compiler = None, cvtres_compiler = None, - archiver = "ar", + archiver = archiver, archiver_type = "gnu", linker = "clang++", linker_type = LinkerType("gnu"),