-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MingW Cross Compiler Toolchain Testing: The current consumer of this toolchain is Starling-Core. This toolchain is limited to an x86_64 Linux host to build an x86_64 Windows target. With this toolchain, we are generating a binary and a static library. The artifacts were generated using CI/CD and were tested on Linux using Wine and on a Windows 11 system. The static library that was generated was also tested on Windows 11 to generate the binary and static data was passed, and the results were compared. The same steps above were also done on an x86_64 Ubuntu 24.04 developer machine.
- Loading branch information
Showing
19 changed files
with
559 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
# Copyright (C) 2024 Swift Navigation Inc. | ||
# Contact: Swift Navigation <[email protected]> | ||
# | ||
# This source is subject to the license found in the file 'LICENSE' which must | ||
# be be distributed together with this source. All other rights reserved. | ||
# | ||
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, | ||
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED | ||
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. | ||
|
||
load(":config.bzl", "config") | ||
|
||
filegroup(name = "empty") | ||
|
||
constraint_value( | ||
name = "llvm_mingw_toolchain", | ||
constraint_setting = "@rules_swiftnav//cc/constraints:toolchain", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "wrappers", | ||
srcs = glob([ | ||
"wrappers/**", | ||
]), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "ar_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:ar", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "as_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:as", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "compiler_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:bin", | ||
"@llvm_mingw_toolchain//:include", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "dwp_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:dwp", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "linker_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:ar", | ||
"@llvm_mingw_toolchain//:clang", | ||
"@llvm_mingw_toolchain//:gcc", | ||
"@llvm_mingw_toolchain//:ld", | ||
"@llvm_mingw_toolchain//:lib", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "objcopy_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:objcopy", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "strip_files", | ||
srcs = [ | ||
":wrappers", | ||
"@llvm_mingw_toolchain//:strip", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = [ | ||
":compiler_files", | ||
":linker_files", | ||
"@llvm_mingw_toolchain//:bin", | ||
], | ||
) | ||
|
||
config(name = "config") | ||
|
||
cc_toolchain( | ||
name = "cc_toolchain", | ||
all_files = ":all_files", | ||
ar_files = ":ar_files", | ||
as_files = ":as_files", | ||
compiler_files = ":compiler_files", | ||
dwp_files = ":empty", | ||
linker_files = ":linker_files", | ||
objcopy_files = ":objcopy_files", | ||
strip_files = ":strip_files", | ||
supports_param_files = 0, | ||
toolchain_config = ":config", | ||
toolchain_identifier = "llvm-mingw", | ||
) | ||
|
||
toolchain( | ||
name = "mingw_toolchain", | ||
exec_compatible_with = [ | ||
"@platforms//cpu:x86_64", | ||
"@platforms//os:linux", | ||
], | ||
target_compatible_with = [ | ||
"@platforms//cpu:x86_64", | ||
"@platforms//os:windows", | ||
], | ||
target_settings = None, | ||
toolchain = ":cc_toolchain", | ||
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "feature", "flag_group", "flag_set", "tool_path", "with_feature_set") | ||
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") | ||
|
||
def _impl(ctx): | ||
SDK_PATH_PREFIX = "wrappers/x86_64-w64-mingw32uwp-{}" | ||
|
||
tool_paths = [ | ||
tool_path( | ||
name = "ar", | ||
path = SDK_PATH_PREFIX.format("ar"), | ||
), | ||
tool_path( | ||
name = "as", | ||
path = SDK_PATH_PREFIX.format("as"), | ||
), | ||
tool_path( | ||
name = "cpp", | ||
path = SDK_PATH_PREFIX.format("cpp"), | ||
), | ||
tool_path( | ||
name = "gcc", | ||
path = SDK_PATH_PREFIX.format("gcc"), | ||
), | ||
tool_path( | ||
name = "g++", | ||
path = SDK_PATH_PREFIX.format("g++"), | ||
), | ||
tool_path( | ||
name = "gcov", | ||
path = SDK_PATH_PREFIX.format("gcov"), | ||
), | ||
tool_path( | ||
name = "ld", | ||
path = SDK_PATH_PREFIX.format("ld"), | ||
), | ||
tool_path( | ||
name = "nm", | ||
path = SDK_PATH_PREFIX.format("nm"), | ||
), | ||
tool_path( | ||
name = "objcopy", | ||
path = SDK_PATH_PREFIX.format("objcopy"), | ||
), | ||
tool_path( | ||
name = "objdump", | ||
path = SDK_PATH_PREFIX.format("objdump"), | ||
), | ||
tool_path( | ||
name = "ranlib", | ||
path = SDK_PATH_PREFIX.format("ranlib"), | ||
), | ||
tool_path( | ||
name = "strip", | ||
path = SDK_PATH_PREFIX.format("strip"), | ||
), | ||
] | ||
|
||
all_compile_actions = [ | ||
ACTION_NAMES.assemble, | ||
ACTION_NAMES.c_compile, | ||
ACTION_NAMES.cpp_compile, | ||
ACTION_NAMES.cpp_header_parsing, | ||
ACTION_NAMES.cpp_module_codegen, | ||
ACTION_NAMES.cpp_module_compile, | ||
ACTION_NAMES.clif_match, | ||
ACTION_NAMES.linkstamp_compile, | ||
ACTION_NAMES.lto_backend, | ||
ACTION_NAMES.preprocess_assemble, | ||
] | ||
|
||
opt_feature = feature(name = "opt") | ||
|
||
features = [ | ||
feature( | ||
name = "default_compile_actions", | ||
enabled = True, | ||
flag_sets = [ | ||
flag_set( | ||
actions = all_compile_actions, | ||
flag_groups = ([ | ||
flag_group( | ||
flags = [ | ||
"--sysroot=external/llvm_mingw_toolchain", | ||
"-no-canonical-prefixes", | ||
# Reproducibility | ||
"-Wno-builtin-macro-redefined", | ||
"-D__DATE__=\"redacted\"", | ||
"-D__TIMESTAMP__=\"redacted\"", | ||
"-D__TIME__=\"redacted\"", | ||
], | ||
), | ||
]), | ||
), | ||
flag_set( | ||
actions = all_compile_actions, | ||
flag_groups = ([ | ||
flag_group( | ||
flags = ["-O2", "-g"], | ||
), | ||
]), | ||
with_features = [with_feature_set(features = ["opt"])], | ||
), | ||
], | ||
), | ||
feature( | ||
name = "default_link_flags", | ||
enabled = True, | ||
flag_sets = [ | ||
flag_set( | ||
actions = [ | ||
ACTION_NAMES.cpp_link_executable, | ||
ACTION_NAMES.cpp_link_dynamic_library, | ||
ACTION_NAMES.cpp_link_nodeps_dynamic_library, | ||
], | ||
flag_groups = ([ | ||
flag_group( | ||
flags = [ | ||
"-lstdc++", | ||
"-lm", | ||
"-static", | ||
], | ||
), | ||
]), | ||
), | ||
], | ||
), | ||
opt_feature, | ||
] | ||
|
||
return cc_common.create_cc_toolchain_config_info( | ||
ctx = ctx, | ||
features = features, | ||
toolchain_identifier = "llvm-mingw", | ||
host_system_name = "local", | ||
target_system_name = "local", | ||
target_cpu = "x86_64", | ||
target_libc = "unknown", | ||
compiler = "llvm", | ||
abi_version = "unknown", | ||
abi_libc_version = "unknown", | ||
tool_paths = tool_paths, | ||
) | ||
|
||
config = rule( | ||
implementation = _impl, | ||
attrs = { | ||
"c_opts": attr.string_list(), | ||
"link_opts": attr.string_list(), | ||
}, | ||
provides = [CcToolchainConfigInfo], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
filegroup( | ||
name = "gcc", | ||
srcs = [ | ||
"bin/x86_64-w64-mingw32uwp-c++", | ||
"bin/x86_64-w64-mingw32uwp-g++", | ||
"bin/x86_64-w64-mingw32uwp-gcc", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "clang", | ||
srcs = [ | ||
"bin/clang-cpp", | ||
"bin/x86_64-w64-mingw32uwp-clang", | ||
"bin/x86_64-w64-mingw32uwp-clang++", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "ld", | ||
srcs = [ | ||
"bin/x86_64-w64-mingw32uwp-ld", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "include", | ||
srcs = glob([ | ||
"x86_64-w64-mingw32/include/**", | ||
"lib/clang/*/include/**", | ||
"generic-w64-mingw32/include/c++/v1/*", | ||
]), | ||
) | ||
|
||
filegroup( | ||
name = "bin", | ||
srcs = glob([ | ||
"bin/**", | ||
"x86_64-w64-mingw32/**", | ||
]), | ||
) | ||
|
||
filegroup( | ||
name = "lib", | ||
srcs = glob([ | ||
"lib/**/lib*.a", | ||
"lib/clang/*/lib/**/*.a", | ||
"x86_64-w64-mingw32/lib/*.a", | ||
]), | ||
) | ||
|
||
filegroup( | ||
name = "ar", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-ar"], | ||
) | ||
|
||
filegroup( | ||
name = "as", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-as"], | ||
) | ||
|
||
filegroup( | ||
name = "nm", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-nm"], | ||
) | ||
|
||
filegroup( | ||
name = "objcopy", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-objcopy"], | ||
) | ||
|
||
filegroup( | ||
name = "objdump", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-objdump"], | ||
) | ||
|
||
filegroup( | ||
name = "ranlib", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-ranlib"], | ||
) | ||
|
||
filegroup( | ||
name = "strip", | ||
srcs = ["bin/x86_64-w64-mingw32uwp-strip"], | ||
) |
Oops, something went wrong.