From 73c57034aa14fcd3fcea58a64db7ae6dad6af08e Mon Sep 17 00:00:00 2001 From: Deanna Garcia Date: Wed, 24 Nov 2021 19:48:16 +0000 Subject: [PATCH] Adding windows toolchains --- toolchain/BUILD | 38 +++++++++++++++++++++++++++++++ toolchain/cc_toolchain_config.bzl | 4 ++++ toolchain/toolchains.bazelrc | 2 ++ 3 files changed, 44 insertions(+) diff --git a/toolchain/BUILD b/toolchain/BUILD index 2b0a8150917f1..46e0348f6e088 100644 --- a/toolchain/BUILD +++ b/toolchain/BUILD @@ -12,6 +12,8 @@ TOOLCHAINS = { "linux-s390_64": "cc-compiler-linux-s390_64", "linux-x86_32": "cc-compiler-linux-x86_32", "linux-x86_64": "cc-compiler-linux-x86_64", + "win32": "cc-compiler-windows-x86_32", + "win64": "cc-compiler-windows-x86_64", } cc_toolchain_suite( @@ -135,3 +137,39 @@ cc_toolchain_config( toolchain_dir = "/usr/tools/apple_sdks/xcode_13_0/macosx", toolchain_name = "darwin_x86_64", ) + +cc_toolchain_config( + name = "win32-config", + bit_flag = "-m32", + cpp_flag = "-lstdc++", + extra_include = "/usr/lib/gcc/i686-w64-mingw32/10-posix/include", + extra_linker_flag = "-L/usr/lib/gcc/i686-w64-mingw32/10-posix", + include_flag = [ + "-I/usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++", + "-I/usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++/i686-w64-mingw32", + "-I/usr/i686-w64-mingw32/include" + ], + linker_path = "/usr/bin/ld", + target_cpu = "x86_32", + target_full_name = "i686-w64-mingw32", + toolchain_dir = "/usr/i686-w64-mingw32/include", + toolchain_name = "i686-w64-mingw32", +) + +cc_toolchain_config( + name = "win64-config", + bit_flag = "-m64", + cpp_flag = "-lstdc++", + extra_include = "/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include", + extra_linker_flag = "-L/usr/lib/gcc/x86_64-w64-mingw32/10-posix", + include_flag = [ + "-I/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/", + "-I/usr/lib/gcc/x86_64-w64-mingw32/10-posix/include/c++/x86_64-w64-mingw32", + "-I/usr/x86_64-w64-mingw32/include" + ], + linker_path = "/usr/bin/ld", + target_cpu = "x86_64", + target_full_name = "x86_64-w64-mingw32", + toolchain_dir = "/usr/x86_64-w64-mingw32/include", + toolchain_name = "x86_64-w64-mingw32", +) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 1c0e33025dd17..f9b92675a48a9 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -86,6 +86,7 @@ def _impl(ctx): "-B" + ctx.attr.linker_path, ctx.attr.cpp_flag, "--target=" + ctx.attr.target_full_name, + ctx.attr.extra_linker_flag, ], ), ], @@ -142,6 +143,7 @@ def _impl(ctx): compiler = "clang", cxx_builtin_include_directories = [ ctx.attr.toolchain_dir, + ctx.attr.extra_include, "/usr/include", "/usr/local/include", "/usr/local/lib/clang", @@ -161,6 +163,8 @@ cc_toolchain_config = rule( "abi_version": attr.string(default = "local"), "bit_flag": attr.string(mandatory = True, values = ["-m32", "-m64"]), "cpp_flag": attr.string(mandatory = True), + "extra_include": attr.string(mandatory = False), + "extra_linker_flag": attr.string(mandatory = False), "include_flag": attr.string_list(), "linker_path": attr.string(mandatory = True), "sysroot": attr.string(mandatory = False), diff --git a/toolchain/toolchains.bazelrc b/toolchain/toolchains.bazelrc index 60fb6a4ea332d..e28aa8051d573 100644 --- a/toolchain/toolchains.bazelrc +++ b/toolchain/toolchains.bazelrc @@ -8,3 +8,5 @@ build:linux-x86_32 --config=cross_config --cpu=linux-x86_32 build:linux-x86_64 --config=cross_config --cpu=linux-x86_64 build:osx-aarch_64 --config=cross_config --cpu=darwin-aarch_64 build:osx-x86_64 --config=cross_config --cpu=darwin-x86_64 +build:win32 --config=cross_config --cpu=win32 +build:win64 --config=cross_config --cpu=win64