load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") load( "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "action_config", "feature", "flag_group", "flag_set", "tool", "tool_path", "variable_with_value", ) _ALL_COMPILE_ACTIONS = [ ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile, ACTION_NAMES.linkstamp_compile, ACTION_NAMES.assemble, ACTION_NAMES.preprocess_assemble, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, ACTION_NAMES.cpp_module_codegen, ACTION_NAMES.clif_match, ACTION_NAMES.lto_backend, ] _CXX_ONLY_COMPILE_ACTIONS = [ ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile, ACTION_NAMES.linkstamp_compile, ACTION_NAMES.cpp_header_parsing, ACTION_NAMES.cpp_module_compile, ACTION_NAMES.cpp_module_codegen, ACTION_NAMES.clif_match, ACTION_NAMES.lto_backend, ] _ASM_COMPILE_ACTIONS = [ ACTION_NAMES.assemble, ACTION_NAMES.preprocess_assemble, ] _ALL_LINK_ACTIONS = [ ACTION_NAMES.cpp_link_executable, ACTION_NAMES.cpp_link_dynamic_library, ACTION_NAMES.cpp_link_nodeps_dynamic_library, ] _ALL_ARCHIVE_ACTIONS = [ ACTION_NAMES.cpp_link_static_library, ] _ALL_LTO_ACTIONS = [ ACTION_NAMES.lto_index_for_executable, ACTION_NAMES.lto_index_for_dynamic_library, ACTION_NAMES.lto_index_for_nodeps_dynamic_library, ] def _impl(ctx): tool_paths = [ tool_path(name = "ar", path = "/usr/bin/ar"), tool_path(name = "compat-ld", path = "/usr/bin/ld"), tool_path(name = "cpp", path = "/usr/bin/cpp"), tool_path(name = "dwp", path = "/usr/bin/dwp"), tool_path(name = "gcc", path = "/usr/bin/gcc"), tool_path(name = "gcov", path = "/usr/bin/gcov"), tool_path(name = "ld", path = "/usr/bin/ld"), tool_path(name = "nm", path = "/usr/bin/nm"), tool_path(name = "objcopy", path = "/usr/bin/objcopy"), tool_path(name = "objdump", path = "/usr/bin/objdump"), tool_path(name = "strip", path = "/usr/bin/strip"), ] compile_action_configs = [ action_config( action_name = name, enabled = True, tools = [tool(path = "/usr/bin/gcc")], ) for name in _ALL_COMPILE_ACTIONS ] link_action_configs = [ action_config( action_name = name, enabled = True, tools = [tool(path = "/usr/bin/gcc")], ) for name in _ALL_LINK_ACTIONS ] archive_action_configs = [ action_config( action_name = name, enabled = True, tools = [tool(path = "/usr/bin/ar")], ) for name in _ALL_ARCHIVE_ACTIONS ] lto_action_configs = [ action_config( action_name = name, enabled = True, tools = [tool(path = "/usr/bin/gcc")], ) for name in _ALL_LTO_ACTIONS ] misc_action_configs = [ action_config( action_name = ACTION_NAMES.strip, enabled = True, tools = [tool(path = "/usr/bin/strip")], ), ] compiler_input_flags = feature( name = "compiler_input_flags", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS, flag_groups = [ flag_group( expand_if_available = "source_file", flags = ["-c", "%{source_file}"], ), ], )], ) compiler_output_flags = feature( name = "compiler_output_flags", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS, flag_groups = [ flag_group( expand_if_available = "output_file", flags = ["-o", "%{output_file}"], ), ], )], ) dependency_file = feature( name = "dependency_file", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS, flag_groups = [ flag_group( expand_if_available = "dependency_file", flags = ["-MD", "-MF", "%{dependency_file}"], ), ], )], ) pic = feature( name = "pic", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS + _ALL_LINK_ACTIONS, flag_groups = [ flag_group(flags = ["-fPIC"], expand_if_available = "pic"), ], )], ) preprocessor_defines = feature( name = "preprocessor_defines", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS, flag_groups = [ flag_group( expand_if_available = "preprocessor_defines", iterate_over = "preprocessor_defines", flags = ["-D%{preprocessor_defines}"], ), ], )], ) includes = feature( name = "includes", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS, flag_groups = [ flag_group( expand_if_available = "quote_include_paths", iterate_over = "quote_include_paths", flags = ["-I%{quote_include_paths}"], ), flag_group( expand_if_available = "include_paths", iterate_over = "include_paths", flags = ["-I%{include_paths}"], ), flag_group( expand_if_available = "external_include_paths", iterate_over = "external_include_paths", flags = ["-isystem", "%{external_include_paths}"], ), flag_group( expand_if_available = "system_include_paths", iterate_over = "system_include_paths", flags = ["-isystem", "%{system_include_paths}"], ), ], )], ) sysroot = feature( name = "sysroot", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS + _ALL_LINK_ACTIONS, flag_groups = [ flag_group( expand_if_available = "sysroot", flags = ["--sysroot=%{sysroot}"], ), ], )], ) user_compile_flags = feature( name = "user_compile_flags", enabled = True, flag_sets = [flag_set( actions = _ALL_COMPILE_ACTIONS, flag_groups = [ flag_group( expand_if_available = "user_compile_flags", iterate_over = "user_compile_flags", flags = ["%{user_compile_flags}"], ), ], )], ) default_compile_flags = feature( name = "default_compile_flags", enabled = True, flag_sets = [ flag_set( actions = _ASM_COMPILE_ACTIONS, flag_groups = [ flag_group(flags = [ "-O2", "-msse4.2", "-D_GNU_SOURCE", "-Wno-error", "-fPIC", "-fcf-protection=full", "-fstack-protector-strong", "-fstack-clash-protection", "-fstrict-flex-arrays=3", "-U_FORTIFY_SOURCE", "-D_FORTIFY_SOURCE=3", ]), ], ), flag_set( actions = _CXX_ONLY_COMPILE_ACTIONS, flag_groups = [ flag_group(flags = [ "-O2", "-msse4.2", "-D_GNU_SOURCE", "-Wno-error", "-include", "bazel/toolchains/cc/system_gcc/preinclude.h", "-fstack-protector-strong", "-fstack-clash-protection", "-fstrict-flex-arrays=3", "-U_FORTIFY_SOURCE", "-D_FORTIFY_SOURCE=3", "-fcf-protection=full", ]), ], ), ], ) linker_flags = feature( name = "linker_flags", enabled = True, flag_sets = [flag_set( actions = _ALL_LINK_ACTIONS, flag_groups = [ flag_group( expand_if_available = "output_execpath", flags = ["-o", "%{output_execpath}"], ), flag_group( expand_if_available = "linker_param_file", flags = ["@%{linker_param_file}"], ), ], )], ) libraries_to_link = feature( name = "libraries_to_link", enabled = True, flag_sets = [flag_set( actions = _ALL_LINK_ACTIONS, flag_groups = [ flag_group( expand_if_available = "libraries_to_link", iterate_over = "libraries_to_link", flag_groups = [ flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "object_file_group", ), expand_if_false = "libraries_to_link.is_whole_archive", flags = ["-Wl,--start-lib"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "static_library", ), expand_if_true = "libraries_to_link.is_whole_archive", flags = ["-Wl,--whole-archive"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "object_file_group", ), iterate_over = "libraries_to_link.object_files", flags = ["%{libraries_to_link.object_files}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "object_file", ), flags = ["%{libraries_to_link.name}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "interface_library", ), flags = ["%{libraries_to_link.name}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "static_library", ), flags = ["%{libraries_to_link.name}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "dynamic_library", ), flags = ["-l%{libraries_to_link.name}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "versioned_dynamic_library", ), flags = ["-l:%{libraries_to_link.name}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "static_library", ), expand_if_true = "libraries_to_link.is_whole_archive", flags = ["-Wl,--no-whole-archive"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "object_file_group", ), expand_if_false = "libraries_to_link.is_whole_archive", flags = ["-Wl,--end-lib"], ), ], ), ], )], ) library_search_directories = feature( name = "library_search_directories", enabled = True, flag_sets = [flag_set( actions = _ALL_LINK_ACTIONS, flag_groups = [ flag_group( expand_if_available = "library_search_directories", iterate_over = "library_search_directories", flags = ["-L%{library_search_directories}"], ), ], )], ) runtime_library_search_directories = feature( name = "runtime_library_search_directories", enabled = True, flag_sets = [flag_set( actions = _ALL_LINK_ACTIONS, flag_groups = [ flag_group( expand_if_available = "runtime_library_search_directories", iterate_over = "runtime_library_search_directories", flags = ["-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}"], ), ], )], ) user_link_flags = feature( name = "user_link_flags", enabled = True, flag_sets = [flag_set( actions = _ALL_LINK_ACTIONS, flag_groups = [ flag_group( expand_if_available = "user_link_flags", iterate_over = "user_link_flags", flags = ["%{user_link_flags}"], ), ], )], ) default_link_flags_exe = feature( name = "default_link_flags_exe", enabled = True, flag_sets = [flag_set( actions = [ACTION_NAMES.cpp_link_executable], flag_groups = [ flag_group(flags = [ "-Wl,-z,relro", "-Wl,-z,now", "-Wl,-z,noexecstack", "-Wl,-z,force-ibt", "-Wl,-z,shstk", "-pie", "-fuse-ld=lld", ]), flag_group(flags = [ "-lstdc++", "-lm", "-ldl", "-lpthread", "-lrt", "-lresolv", "-lgcc_s", "-lgcc", "-lc", ]), ], )], ) default_link_flags_shared = feature( name = "default_link_flags_shared", enabled = True, flag_sets = [flag_set( actions = [ ACTION_NAMES.cpp_link_dynamic_library, ACTION_NAMES.cpp_link_nodeps_dynamic_library, ], flag_groups = [ flag_group(flags = [ "-Wl,-z,relro", "-Wl,-z,now", "-Wl,-z,noexecstack", "-Wl,-z,force-ibt", "-Wl,-z,shstk", "-shared", "-fuse-ld=lld", ]), flag_group(flags = [ "-lstdc++", "-lm", "-ldl", "-lpthread", "-lrt", "-lresolv", "-lgcc_s", "-lgcc", "-lc", ]), ], )], ) archiver_flags = feature( name = "archiver_flags", enabled = True, flag_sets = [flag_set( actions = _ALL_ARCHIVE_ACTIONS, flag_groups = [ flag_group(flags = ["rcsD"]), flag_group( expand_if_available = "output_execpath", flags = ["%{output_execpath}"], ), flag_group( expand_if_available = "libraries_to_link", iterate_over = "libraries_to_link", flag_groups = [ flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "object_file", ), flags = ["%{libraries_to_link.name}"], ), flag_group( expand_if_equal = variable_with_value( name = "libraries_to_link.type", value = "object_file_group", ), iterate_over = "libraries_to_link.object_files", flags = ["%{libraries_to_link.object_files}"], ), ], ), ], )], ) features = [ compiler_input_flags, compiler_output_flags, dependency_file, pic, preprocessor_defines, includes, sysroot, user_compile_flags, default_compile_flags, linker_flags, libraries_to_link, library_search_directories, runtime_library_search_directories, user_link_flags, default_link_flags_exe, default_link_flags_shared, archiver_flags, feature(name = "supports_pic", enabled = True), feature(name = "supports_dynamic_linker", enabled = True), feature(name = "has_configured_linker_path", enabled = True), ] return cc_common.create_cc_toolchain_config_info( ctx = ctx, features = features, action_configs = ( compile_action_configs + link_action_configs + archive_action_configs + lto_action_configs + misc_action_configs ), toolchain_identifier = "system-gcc-16", host_system_name = "local", target_system_name = "local", target_cpu = "k8", target_libc = "local", compiler = "gcc", abi_version = "local", abi_libc_version = "local", tool_paths = tool_paths, cxx_builtin_include_directories = [ "/usr/include/c++/16.2.0", "/usr/include/c++/16.2.0/x86_64-slackware-linux", "/usr/include/c++/16.2.0/backward", "/usr/lib64/gcc/x86_64-slackware-linux/16.2.0/include", "/usr/lib64/gcc/x86_64-slackware-linux/16.2.0/include-fixed", "/usr/local/include", "/usr/include", ], ) cc_toolchain_config = rule( implementation = _impl, attrs = {}, provides = [CcToolchainConfigInfo], )