|
| 1 | +load( |
| 2 | + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", |
| 3 | + "action_config", |
| 4 | + "feature", |
| 5 | + "feature_set", |
| 6 | + "flag_group", |
| 7 | + "flag_set", |
| 8 | + "make_variable", |
| 9 | + "tool", |
| 10 | + "tool_path", |
| 11 | + "with_feature_set", |
| 12 | + "artifact_name_pattern", |
| 13 | + "env_set", |
| 14 | + "env_entry", |
| 15 | +) |
| 16 | + |
| 17 | +load( |
| 18 | + "@bazel_tools//tools/cpp:cc_toolchain_config.bzl", |
| 19 | + ALL_COMPILE_ACTIONS = "all_compile_actions", |
| 20 | + ALL_CPP_COMPILE_ACTIONS = "all_cpp_compile_actions", |
| 21 | + ALL_LINK_ACTIONS = "all_link_actions", |
| 22 | +) |
| 23 | + |
| 24 | +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") |
| 25 | + |
| 26 | +def _impl(ctx): |
| 27 | + toolchain_identifier = "msys_x64_mingw" |
| 28 | + host_system_name = "local" |
| 29 | + target_system_name = "local" |
| 30 | + target_cpu = "x64_windows" |
| 31 | + target_libc = "mingw" |
| 32 | + compiler = "mingw-gcc" |
| 33 | + abi_version = "local" |
| 34 | + abi_libc_version = "local" |
| 35 | + cc_target_os = None |
| 36 | + builtin_sysroot = None |
| 37 | + action_configs = [] |
| 38 | + |
| 39 | + install = "/usr/x86_64-w64-mingw32/" |
| 40 | + bin_prefix = "/usr/bin/x86_64-w64-mingw32-" |
| 41 | + |
| 42 | + |
| 43 | + targets_windows_feature = feature( |
| 44 | + name = "targets_windows", |
| 45 | + implies = ["copy_dynamic_libraries_to_binary"], |
| 46 | + enabled = True, |
| 47 | + ) |
| 48 | + |
| 49 | + copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary") |
| 50 | + |
| 51 | + gcc_env_feature = feature( |
| 52 | + name = "gcc_env", |
| 53 | + enabled = True, |
| 54 | + env_sets = [ |
| 55 | + env_set( |
| 56 | + actions = [ |
| 57 | + ACTION_NAMES.c_compile, |
| 58 | + ACTION_NAMES.cpp_compile, |
| 59 | + ACTION_NAMES.cpp_module_compile, |
| 60 | + ACTION_NAMES.cpp_module_codegen, |
| 61 | + ACTION_NAMES.cpp_header_parsing, |
| 62 | + ACTION_NAMES.assemble, |
| 63 | + ACTION_NAMES.preprocess_assemble, |
| 64 | + ACTION_NAMES.cpp_link_executable, |
| 65 | + ACTION_NAMES.cpp_link_dynamic_library, |
| 66 | + ACTION_NAMES.cpp_link_nodeps_dynamic_library, |
| 67 | + ACTION_NAMES.cpp_link_static_library, |
| 68 | + ], |
| 69 | + env_entries = [ |
| 70 | + env_entry(key = "PATH", value = "NOT_USED"), |
| 71 | + ], |
| 72 | + ), |
| 73 | + ], |
| 74 | + ) |
| 75 | + |
| 76 | + msys_mingw_flags = [ |
| 77 | + "-B " + install + "bin", |
| 78 | + "-nostdinc", |
| 79 | + "-U_FORTIFY_SOURCE", |
| 80 | + "-fstack-protector", |
| 81 | + "-fno-omit-frame-pointer", |
| 82 | + "-fcolor-diagnostics", |
| 83 | + "-Wall", |
| 84 | + "-Wthread-safety", |
| 85 | + "-Wself-assign", |
| 86 | + "-x c++", |
| 87 | + "-lstdc++", |
| 88 | + "-lpthread" |
| 89 | + ] |
| 90 | + |
| 91 | + msys_mingw_link_flags = [ |
| 92 | + "-l:libstdc++.a", |
| 93 | + "-L" + install + "lib", |
| 94 | + "-L/usr/lib/gcc/x86_64-w64-mingw32/8.3-w32", |
| 95 | + "-v", |
| 96 | + "-lm", |
| 97 | + "-no-canonical-prefixes", |
| 98 | + ] |
| 99 | + |
| 100 | + default_compile_flags_feature = feature( |
| 101 | + name = "default_compile_flags", |
| 102 | + enabled = True, |
| 103 | + flag_sets = [ |
| 104 | + flag_set( |
| 105 | + actions = [ |
| 106 | + ACTION_NAMES.assemble, |
| 107 | + ACTION_NAMES.preprocess_assemble, |
| 108 | + ACTION_NAMES.linkstamp_compile, |
| 109 | + ACTION_NAMES.c_compile, |
| 110 | + ACTION_NAMES.cpp_compile, |
| 111 | + ACTION_NAMES.cpp_header_parsing, |
| 112 | + ACTION_NAMES.cpp_module_compile, |
| 113 | + ACTION_NAMES.cpp_module_codegen, |
| 114 | + ACTION_NAMES.lto_backend, |
| 115 | + ACTION_NAMES.clif_match, |
| 116 | + ], |
| 117 | + ), |
| 118 | + flag_set( |
| 119 | + actions = [ |
| 120 | + ACTION_NAMES.linkstamp_compile, |
| 121 | + ACTION_NAMES.cpp_compile, |
| 122 | + ACTION_NAMES.cpp_header_parsing, |
| 123 | + ACTION_NAMES.cpp_module_compile, |
| 124 | + ACTION_NAMES.cpp_module_codegen, |
| 125 | + ACTION_NAMES.lto_backend, |
| 126 | + ACTION_NAMES.clif_match, |
| 127 | + ], |
| 128 | + flag_groups = ([flag_group(flags = msys_mingw_flags)] if msys_mingw_flags else []), |
| 129 | + ), |
| 130 | + ], |
| 131 | + ) |
| 132 | + |
| 133 | + compiler_param_file_feature = feature( |
| 134 | + name = "compiler_param_file", |
| 135 | + ) |
| 136 | + |
| 137 | + default_link_flags_feature = feature( |
| 138 | + name = "default_link_flags", |
| 139 | + enabled = True, |
| 140 | + flag_sets = [ |
| 141 | + flag_set( |
| 142 | + actions = ALL_LINK_ACTIONS, |
| 143 | + flag_groups = ([flag_group(flags = msys_mingw_link_flags)] if msys_mingw_link_flags else []), |
| 144 | + ), |
| 145 | + ], |
| 146 | + ) |
| 147 | + |
| 148 | + supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) |
| 149 | + |
| 150 | + features = [ |
| 151 | + targets_windows_feature, |
| 152 | + copy_dynamic_libraries_to_binary_feature, |
| 153 | + gcc_env_feature, |
| 154 | + default_compile_flags_feature, |
| 155 | + compiler_param_file_feature, |
| 156 | + default_link_flags_feature, |
| 157 | + supports_dynamic_linker_feature, |
| 158 | + ] |
| 159 | + |
| 160 | + cxx_builtin_include_directories = [ |
| 161 | + install +"include" |
| 162 | + ] |
| 163 | + |
| 164 | + artifact_name_patterns = [ |
| 165 | + artifact_name_pattern( |
| 166 | + category_name = "executable", |
| 167 | + prefix = "", |
| 168 | + extension = ".exe", |
| 169 | + ), |
| 170 | + ] |
| 171 | + |
| 172 | + make_variables = [] |
| 173 | + tool_paths = [ |
| 174 | + tool_path(name = "ld", path = bin_prefix + "ld"), |
| 175 | + tool_path(name = "cpp", path = bin_prefix + "cpp"), |
| 176 | + tool_path(name = "gcov", path = "/usr/bin/gcov"), |
| 177 | + tool_path(name = "nm", path = bin_prefix + "nm"), |
| 178 | + tool_path(name = "objcopy", path = bin_prefix + "objcopy"), |
| 179 | + tool_path(name = "objdump", path = bin_prefix + "objdump"), |
| 180 | + tool_path(name = "strip", path = bin_prefix + "strip"), |
| 181 | + tool_path(name = "gcc", path = bin_prefix + "gcc"), |
| 182 | + tool_path(name = "ar", path = bin_prefix + "ar"), |
| 183 | + ] |
| 184 | + |
| 185 | + return cc_common.create_cc_toolchain_config_info( |
| 186 | + ctx = ctx, |
| 187 | + features = features, |
| 188 | + action_configs = action_configs, |
| 189 | + artifact_name_patterns = artifact_name_patterns, |
| 190 | + cxx_builtin_include_directories = cxx_builtin_include_directories, |
| 191 | + toolchain_identifier = toolchain_identifier, |
| 192 | + host_system_name = host_system_name, |
| 193 | + target_system_name = target_system_name, |
| 194 | + target_cpu = target_cpu, |
| 195 | + target_libc = target_libc, |
| 196 | + compiler = compiler, |
| 197 | + abi_version = abi_version, |
| 198 | + abi_libc_version = abi_libc_version, |
| 199 | + tool_paths = tool_paths, |
| 200 | + make_variables = make_variables, |
| 201 | + builtin_sysroot = builtin_sysroot, |
| 202 | + cc_target_os = cc_target_os, |
| 203 | + ) |
| 204 | + |
| 205 | +windows_cc_toolchain_config = rule( |
| 206 | + implementation = _impl, |
| 207 | + attrs = { |
| 208 | + "target": attr.string(mandatory = True), |
| 209 | + "stdlib": attr.string(), |
| 210 | + }, |
| 211 | + provides = [CcToolchainConfigInfo], |
| 212 | +) |
| 213 | + |
0 commit comments