From 9a261f799312bbaae80afd317fa6b193c8feec12 Mon Sep 17 00:00:00 2001 From: irengrig Date: Thu, 6 Dec 2018 18:14:00 +0100 Subject: [PATCH] Crosstool example + fixes (#174) * Add crosstool example; does not work with cmake rule yet the code is taken from Bazel test data (bazel_toolchain_test_data) * Make crosstool compilation of cmake_external + cc_binary work To build example, cd examples/cmake_crosstool bazel build //:libhello_test Changes: 1) Initially suggested in #124: put $EXT_BUILD_ROOT on path, so that relative paths can be resolved by CMake 2) Toolchain tools are references as relative paths, and they themselves refer to external repository with external/ prefix. This will not work with CMake, as CMake also perform compiler tests and the build is performed in some temp directory. We need to convert to absolute paths. I did a trick with checking of $EXT_BUILD_ROOT is defined and then using it as a prefix. 3) I had to change the visibility of the cc-compiler-k8 toolchain to public 4) For CMake crosstool file, CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, CMAKE_AR need to be absolute, so in cases when they are relative and not under external directory, force paths conversion --- examples/cmake_crosstool/.bazelrc | 2 + examples/cmake_crosstool/BUILD | 29 +++ examples/cmake_crosstool/WORKSPACE | 22 ++ .../compilers/linaro_linux_gcc_5.3.1.BUILD | 81 +++++++ examples/cmake_crosstool/hello.cc | 23 ++ examples/cmake_crosstool/static/BUILD | 133 +++++++++++ .../cmake_crosstool/static/CMakeLists.txt | 8 + .../cmake_crosstool/static/hello_client.c | 7 + .../static/hello_client_version123.c | 7 + .../cmake_crosstool/static/src/CMakeLists.txt | 16 ++ examples/cmake_crosstool/static/src/hello.c | 7 + examples/cmake_crosstool/static/src/hello.h | 8 + examples/cmake_crosstool/static/test_hello.sh | 3 + .../cmake_crosstool/tools/arm_compiler/BUILD | 107 +++++++++ .../tools/arm_compiler/CROSSTOOL | 218 ++++++++++++++++++ .../tools/arm_compiler/linaro_linux_gcc/BUILD | 85 +++++++ .../linaro_linux_gcc/arm-linux-gnueabihf-ar | 11 + .../linaro_linux_gcc/arm-linux-gnueabihf-as | 5 + .../linaro_linux_gcc/arm-linux-gnueabihf-gcc | 12 + .../linaro_linux_gcc/arm-linux-gnueabihf-ld | 5 + .../linaro_linux_gcc/arm-linux-gnueabihf-nm | 5 + .../arm-linux-gnueabihf-objcopy | 5 + .../arm-linux-gnueabihf-objdump | 5 + .../arm-linux-gnueabihf-strip | 5 + test/cmake_text_tests.bzl | 18 +- tools/build_defs/cmake_script.bzl | 11 +- .../new_11_2018/cc_toolchain_util.bzl | 6 +- tools/build_defs/new_11_2018/framework.bzl | 1 + .../old_10_2018/cc_toolchain_util.bzl | 6 +- tools/build_defs/old_10_2018/framework.bzl | 1 + .../old_11_2018/cc_toolchain_util.bzl | 6 +- tools/build_defs/old_11_2018/framework.bzl | 1 + 32 files changed, 842 insertions(+), 17 deletions(-) create mode 100644 examples/cmake_crosstool/.bazelrc create mode 100644 examples/cmake_crosstool/BUILD create mode 100644 examples/cmake_crosstool/WORKSPACE create mode 100644 examples/cmake_crosstool/compilers/linaro_linux_gcc_5.3.1.BUILD create mode 100644 examples/cmake_crosstool/hello.cc create mode 100644 examples/cmake_crosstool/static/BUILD create mode 100644 examples/cmake_crosstool/static/CMakeLists.txt create mode 100644 examples/cmake_crosstool/static/hello_client.c create mode 100644 examples/cmake_crosstool/static/hello_client_version123.c create mode 100644 examples/cmake_crosstool/static/src/CMakeLists.txt create mode 100644 examples/cmake_crosstool/static/src/hello.c create mode 100644 examples/cmake_crosstool/static/src/hello.h create mode 100644 examples/cmake_crosstool/static/test_hello.sh create mode 100644 examples/cmake_crosstool/tools/arm_compiler/BUILD create mode 100644 examples/cmake_crosstool/tools/arm_compiler/CROSSTOOL create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/BUILD create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ar create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-as create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ld create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-nm create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objcopy create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objdump create mode 100755 examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-strip diff --git a/examples/cmake_crosstool/.bazelrc b/examples/cmake_crosstool/.bazelrc new file mode 100644 index 00000000..fc07d4b3 --- /dev/null +++ b/examples/cmake_crosstool/.bazelrc @@ -0,0 +1,2 @@ +build --crosstool_top=//tools/arm_compiler:toolchain --cpu=armeabi-v7a --spawn_strategy=standalone --experimental_cc_skylark_api_enabled_packages=@rules_foreign_cc//tools/build_defs,tools/build_defs,@foreign_cc_impl +test --crosstool_top=//tools/arm_compiler:toolchain --cpu=armeabi-v7a --spawn_strategy=standalone --experimental_cc_skylark_api_enabled_packages=@rules_foreign_cc//tools/build_defs,tools/build_defs,@foreign_cc_impl \ No newline at end of file diff --git a/examples/cmake_crosstool/BUILD b/examples/cmake_crosstool/BUILD new file mode 100644 index 00000000..75157a37 --- /dev/null +++ b/examples/cmake_crosstool/BUILD @@ -0,0 +1,29 @@ +load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external") + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//src/test/shell/bazel/testdata:__pkg__"], +) + +cc_library( + name = "hello", + srcs = ["hello.cc"], +) + +cmake_external( + name = "hello_cmake", + lib_source = "//static:srcs", + generate_crosstool_file = True, + static_libraries = ["libhello.a"], + out_include_dir = "include/version123", +) + +# I do not make it a test, since it is a cross-compilation example, +# requires test that just checks something about output +cc_binary( + name = "libhello_test", + # includes just hello.h, include directory: "include/version123" + srcs = ["//static:hello_client.c"], + deps = [":hello_cmake"], +) diff --git a/examples/cmake_crosstool/WORKSPACE b/examples/cmake_crosstool/WORKSPACE new file mode 100644 index 00000000..344124d7 --- /dev/null +++ b/examples/cmake_crosstool/WORKSPACE @@ -0,0 +1,22 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "org_linaro_components_toolchain_gcc_5_3_1", + build_file = "@//:compilers/linaro_linux_gcc_5.3.1.BUILD", + strip_prefix = "gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf", + url = "https://bazel-mirror.storage.googleapis.com/releases.linaro.org/components/toolchain/binaries/latest-5/arm-linux-gnueabihf/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf.tar.xz", +) + +local_repository( + name = "rules_foreign_cc", + path = "../..", +) + +load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies") + +rules_foreign_cc_dependencies() + +local_repository( + name = "cmake_hello_world_lib", + path = "../cmake_hello_world_lib/static", +) \ No newline at end of file diff --git a/examples/cmake_crosstool/compilers/linaro_linux_gcc_5.3.1.BUILD b/examples/cmake_crosstool/compilers/linaro_linux_gcc_5.3.1.BUILD new file mode 100644 index 00000000..b231d018 --- /dev/null +++ b/examples/cmake_crosstool/compilers/linaro_linux_gcc_5.3.1.BUILD @@ -0,0 +1,81 @@ +package(default_visibility = ['//visibility:public']) + +filegroup( + name = 'gcc', + srcs = [ + 'bin/arm-linux-gnueabihf-gcc', + ], +) + +filegroup( + name = 'ar', + srcs = [ + 'bin/arm-linux-gnueabihf-ar', + ], +) + +filegroup( + name = 'ld', + srcs = [ + 'bin/arm-linux-gnueabihf-ld', + ], +) + +filegroup( + name = 'nm', + srcs = [ + 'bin/arm-linux-gnueabihf-nm', + ], +) + +filegroup( + name = 'objcopy', + srcs = [ + 'bin/arm-linux-gnueabihf-objcopy', + ], +) + +filegroup( + name = 'objdump', + srcs = [ + 'bin/arm-linux-gnueabihf-objdump', + ], +) + +filegroup( + name = 'strip', + srcs = [ + 'bin/arm-linux-gnueabihf-strip', + ], +) + +filegroup( + name = 'as', + srcs = [ + 'bin/arm-linux-gnueabihf-as', + ], +) + +filegroup( + name = 'compiler_pieces', + srcs = glob([ + 'arm-linux-gnueabihf/**', + 'libexec/**', + 'lib/gcc/arm-linux-gnueabihf/**', + 'include/**', + ]), +) + +filegroup( + name = 'compiler_components', + srcs = [ + ':gcc', + ':ar', + ':ld', + ':nm', + ':objcopy', + ':objdump', + ':strip', + ':as', + ], +) diff --git a/examples/cmake_crosstool/hello.cc b/examples/cmake_crosstool/hello.cc new file mode 100644 index 00000000..b41be6d1 --- /dev/null +++ b/examples/cmake_crosstool/hello.cc @@ -0,0 +1,23 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include +#include + +int main(int argc, char* argv[]) { + std::cout << "Hello! sqrt(time) = " << std::sqrt(time(NULL)) << std::endl; + return EXIT_SUCCESS; +} diff --git a/examples/cmake_crosstool/static/BUILD b/examples/cmake_crosstool/static/BUILD new file mode 100644 index 00000000..1955949c --- /dev/null +++ b/examples/cmake_crosstool/static/BUILD @@ -0,0 +1,133 @@ +# example code is taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib +# for test only + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) + +exports_files([ + "hello_client.c" +]) + +load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cmake_external") + +cmake_external( + name = "libhello", + lib_source = ":srcs", + # pass include/version123 to C/C++ provider as include directory + out_include_dir = "include/version123", +) + +cmake_external( + name = "libhello_win", + cmake_options = ["-G \"Visual Studio 15 2017 Win64\""], + generate_crosstool_file = True, + lib_name = "libhello", + lib_source = ":srcs", + make_commands = ["MSBuild.exe INSTALL.vcxproj"], + # pass include/version123 to C/C++ provider as include directory + out_include_dir = "include/version123", + static_libraries = ["hello.lib"], +) + +cmake_external( + name = "libhello_win_ninja", + cmake_options = ["-GNinja"], + generate_crosstool_file = True, + lib_source = ":srcs", + make_commands = [ + "ninja", + "ninja install", + ], + # pass include/version123 to C/C++ provider as include directory + out_include_dir = "include/version123", + static_libraries = ["hello.lib"], +) + +cmake_external( + name = "libhello_win_nmake", + cmake_options = ["-G \"NMake Makefiles\""], + generate_crosstool_file = True, + lib_source = ":srcs", + make_commands = [ + "nmake", + "nmake install", + ], + # pass include/version123 to C/C++ provider as include directory + out_include_dir = "include/version123", + static_libraries = ["hello.lib"], +) + +cc_binary( + name = "libhello_example", + # includes just hello.h, include directory: "include/version123" + srcs = ["hello_client.c"], + deps = select({ + "@bazel_tools//src/conditions:windows": [":libhello_win"], + "//conditions:default": [":libhello"], + }), +) + +cc_binary( + name = "libhello_example_ninja", + # includes just hello.h, include directory: "include/version123" + srcs = ["hello_client.c"], + deps = select({ + "@bazel_tools//src/conditions:windows": [":libhello_win_ninja"], + "//conditions:default": [":libhello"], + }), +) + +cc_binary( + name = "libhello_example_nmake", + # includes just hello.h, include directory: "include/version123" + srcs = ["hello_client.c"], + deps = select({ + "@bazel_tools//src/conditions:windows": [":libhello_win_nmake"], + "//conditions:default": [":libhello"], + }), +) + +sh_test( + name = "test_hello", + srcs = ["test_hello.sh"], + args = ["libhello_example"], + data = [":libhello_example"], + tags = ["windows"], + visibility = ["//:__pkg__"], +) + +sh_test( + name = "test_hello_ninja", + srcs = ["test_hello.sh"], + args = ["libhello_example_ninja"], + data = [":libhello_example_ninja"], + tags = ["windows"], + visibility = ["//:__pkg__"], +) + +sh_test( + name = "test_hello_nmake", + srcs = ["test_hello.sh"], + args = ["libhello_example_nmake"], + data = [":libhello_example_nmake"], + tags = ["windows"], + visibility = ["//:__pkg__"], +) + +cmake_external( + name = "libhello123", + lib_source = ":srcs", + out_include_dir = "include", + # the name of the static library != .a, put it explicitly + static_libraries = ["libhello.a"], +) + +cc_binary( + name = "libhello_example123", + # includes version123/hello.h, include directory: "include" + srcs = ["hello_client_version123.c"], + deps = [":libhello123"], +) diff --git a/examples/cmake_crosstool/static/CMakeLists.txt b/examples/cmake_crosstool/static/CMakeLists.txt new file mode 100644 index 00000000..4e1188e9 --- /dev/null +++ b/examples/cmake_crosstool/static/CMakeLists.txt @@ -0,0 +1,8 @@ +# taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib +# for test only + +cmake_minimum_required(VERSION 2.8.4) + +project(hellolib) + +add_subdirectory(src) \ No newline at end of file diff --git a/examples/cmake_crosstool/static/hello_client.c b/examples/cmake_crosstool/static/hello_client.c new file mode 100644 index 00000000..6ec7b354 --- /dev/null +++ b/examples/cmake_crosstool/static/hello_client.c @@ -0,0 +1,7 @@ +#include "hello.h" + +int main(int argc, char* argv[]) +{ + hello_func(); + return 0; +} \ No newline at end of file diff --git a/examples/cmake_crosstool/static/hello_client_version123.c b/examples/cmake_crosstool/static/hello_client_version123.c new file mode 100644 index 00000000..deb3b701 --- /dev/null +++ b/examples/cmake_crosstool/static/hello_client_version123.c @@ -0,0 +1,7 @@ +#include "version123/hello.h" + +int main(int argc, char* argv[]) +{ + hello_func(); + return 0; +} \ No newline at end of file diff --git a/examples/cmake_crosstool/static/src/CMakeLists.txt b/examples/cmake_crosstool/static/src/CMakeLists.txt new file mode 100644 index 00000000..4b49a7af --- /dev/null +++ b/examples/cmake_crosstool/static/src/CMakeLists.txt @@ -0,0 +1,16 @@ +# taken from https://github.com/Akagi201/learning-cmake/tree/master/hello-world-lib +# for test only + +cmake_minimum_required(VERSION 2.8.4) + +set(LIBHELLO_SRC hello.c) + +add_library(hello_static STATIC ${LIBHELLO_SRC}) + +set_target_properties(hello_static PROPERTIES OUTPUT_NAME "hello") + +set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) + +install(TARGETS hello_static ARCHIVE DESTINATION lib) + +install(FILES hello.h DESTINATION include/version123) \ No newline at end of file diff --git a/examples/cmake_crosstool/static/src/hello.c b/examples/cmake_crosstool/static/src/hello.c new file mode 100644 index 00000000..740ba68c --- /dev/null +++ b/examples/cmake_crosstool/static/src/hello.c @@ -0,0 +1,7 @@ +#include "hello.h" + +void hello_func(void) { + printf("Hello World!\n"); + + return; +} \ No newline at end of file diff --git a/examples/cmake_crosstool/static/src/hello.h b/examples/cmake_crosstool/static/src/hello.h new file mode 100644 index 00000000..857e1e24 --- /dev/null +++ b/examples/cmake_crosstool/static/src/hello.h @@ -0,0 +1,8 @@ +#ifndef HELLO_H_ +#define HELLO_H_ (1) + +#include + +void hello_func(void); + +#endif \ No newline at end of file diff --git a/examples/cmake_crosstool/static/test_hello.sh b/examples/cmake_crosstool/static/test_hello.sh new file mode 100644 index 00000000..06092d63 --- /dev/null +++ b/examples/cmake_crosstool/static/test_hello.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +$(rlocation rules_foreign_cc/examples/cmake_hello_world_lib/$1) \ No newline at end of file diff --git a/examples/cmake_crosstool/tools/arm_compiler/BUILD b/examples/cmake_crosstool/tools/arm_compiler/BUILD new file mode 100644 index 00000000..f188e7b7 --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/BUILD @@ -0,0 +1,107 @@ +# This is the entry point for --crosstool_top. Toolchains are found +# by lopping off the name of --crosstool_top and searching for +# 'cc-compiler-${CPU}' in this BUILD file, where CPU is the target CPU +# specified in --cpu. +# +# This file group should include +# * all cc_toolchain targets supported +# * all file groups that said cc_toolchain might refer to, +# including the default_grte_top setting in the CROSSTOOL +# protobuf. +filegroup( + name = "toolchain_fg", + srcs = [ + ":cc-compiler-armeabi-v7a", + ":cc-compiler-k8", + ":linaro_linux_all_files", + "@org_linaro_components_toolchain_gcc_5_3_1//:compiler_components", + ], +) + +filegroup( + name = "srcs", + srcs = glob(["**"]) + [ + "//src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler/linaro_linux_gcc:srcs", + ], + visibility = ["//src/test/shell/bazel/testdata/bazel_toolchain_test_data:__pkg__"], +) + +cc_toolchain_suite( + name = "toolchain", + # target_cpu | compiler + toolchains = { + "armeabi-v7a": "cc-compiler-armeabi-v7a", + "k8": "cc-compiler-k8", + "armeabi-v7a|gcc": "cc-compiler-armeabi-v7a", + "k8|compiler": "cc-compiler-k8", + }, + visibility = ["//visibility:public"], +) + +filegroup( + name = "linaro_linux_all_files", + srcs = [ + "//tools/arm_compiler/linaro_linux_gcc:tool-wrappers", + "@org_linaro_components_toolchain_gcc_5_3_1//:compiler_pieces", + ], +) + +filegroup( + name = "linaro_linux_linker_files", + srcs = [ + "//tools/arm_compiler/linaro_linux_gcc:ar", + "//tools/arm_compiler/linaro_linux_gcc:gcc", + "//tools/arm_compiler/linaro_linux_gcc:ld", + "@org_linaro_components_toolchain_gcc_5_3_1//:compiler_pieces", + ], +) + +filegroup( + name = "linaro_linux_compiler_files", + srcs = [ + "//tools/arm_compiler/linaro_linux_gcc:as", + "//tools/arm_compiler/linaro_linux_gcc:gcc", + "//tools/arm_compiler/linaro_linux_gcc:ld", + ], +) + +filegroup( + name = "empty", + srcs = [], +) + +cc_toolchain( + name = "cc-compiler-armeabi-v7a", + toolchain_identifier = "armeabi-v7a", + all_files = ":linaro_linux_all_files", + ar_files = "//tools/arm_compiler/linaro_linux_gcc:ar", + as_files = "//tools/arm_compiler/linaro_linux_gcc:as", + compiler_files = ":linaro_linux_compiler_files", + cpu = "armeabi-v7a", + dwp_files = ":empty", + dynamic_runtime_libs = [":empty"], + linker_files = ":linaro_linux_linker_files", + objcopy_files = "//tools/arm_compiler/linaro_linux_gcc:objcopy", + static_runtime_libs = [":empty"], + strip_files = "//tools/arm_compiler/linaro_linux_gcc:strip", + supports_param_files = 1, + visibility = ["//visibility:public"], +) + +cc_toolchain( + name = "cc-compiler-k8", + toolchain_identifier = "local", + all_files = ":empty", + ar_files = ":empty", + as_files = ":empty", + compiler_files = ":empty", + cpu = "local", + dwp_files = ":empty", + dynamic_runtime_libs = [":empty"], + linker_files = ":empty", + objcopy_files = ":empty", + static_runtime_libs = [":empty"], + strip_files = ":empty", + supports_param_files = 1, + visibility = ["//visibility:public"], +) diff --git a/examples/cmake_crosstool/tools/arm_compiler/CROSSTOOL b/examples/cmake_crosstool/tools/arm_compiler/CROSSTOOL new file mode 100644 index 00000000..55148f0d --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/CROSSTOOL @@ -0,0 +1,218 @@ +major_version: "local" +minor_version: "" + +toolchain { + abi_version: "gcc" + abi_libc_version: "glibc_2.19" + builtin_sysroot: "" + compiler: "gcc" + host_system_name: "armeabi-v7a" + needsPic: true + supports_gold_linker: false + supports_incremental_linker: false + supports_fission: false + supports_interface_shared_objects: false + supports_normalizing_ar: true + supports_start_end_lib: false + supports_thin_archives: true + target_libc: "glibc_2.19" + target_cpu: "armeabi-v7a" + target_system_name: "arm_a15" + toolchain_identifier: "armeabi-v7a" + + tool_path { name: "ar" path: "linaro_linux_gcc/arm-linux-gnueabihf-ar" } + tool_path { name: "compat-ld" path: "linaro_linux_gcc/arm-linux-gnueabihf-ld" } + tool_path { name: "cpp" path: "linaro_linux_gcc/arm-linux-gnueabihf-gcc" } + tool_path { name: "dwp" path: "linaro_linux_gcc/arm-linux-gnueabihf-dwp" } + tool_path { name: "gcc" path: "linaro_linux_gcc/arm-linux-gnueabihf-gcc" } + tool_path { name: "gcov" path: "arm-frc-linux-gnueabi/arm-frc-linux-gnueabi-gcov-4.9" } + # C(++) compiles invoke the compiler (as that is the one knowing where + # to find libraries), but we provide LD so other rules can invoke the linker. + tool_path { name: "ld" path: "linaro_linux_gcc/arm-linux-gnueabihf-ld" } + tool_path { name: "nm" path: "linaro_linux_gcc/arm-linux-gnueabihf-nm" } + tool_path { name: "objcopy" path: "linaro_linux_gcc/arm-linux-gnueabihf-objcopy" } + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + tool_path { name: "objdump" path: "linaro_linux_gcc/arm-linux-gnueabihf-objdump" } + tool_path { name: "strip" path: "linaro_linux_gcc/arm-linux-gnueabihf-strip" } + + compiler_flag: "--sysroot=external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc" + compiler_flag: "-mfloat-abi=hard" + + compiler_flag: "-nostdinc" + compiler_flag: "-isystem" + compiler_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/lib/gcc/arm-linux-gnueabihf/5.3.1/include" + compiler_flag: "-isystem" + compiler_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/include" + compiler_flag: "-isystem" + compiler_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/lib/gcc/arm-linux-gnueabihf/5.3.1/include-fixed" + compiler_flag: "-isystem" + compiler_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/include" + cxx_flag: "-isystem" + cxx_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/include/c++/5.3.1/arm-linux-gnueabihf" + cxx_flag: "-isystem" + cxx_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/include/c++/5.3.1" + cxx_flag: "-isystem" + cxx_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/include/c++/5.3.1/arm-linux-gnueabihf" + cxx_flag: "-isystem" + cxx_flag: "external/org_linaro_components_toolchain_gcc_5_3_1/include/c++/5.3.1" + + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//include)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//arm-linux-gnueabihf/libc/usr/include)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//arm-linux-gnueabihf/libc/usr/lib/include)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/5.3.1/include-fixed)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//include)%/c++/5.3.1" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/5.3.1/include)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//arm-linux-gnueabihf/libc/lib/gcc/arm-linux-gnueabihf/5.3.1/include-fixed)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//lib/gcc/arm-linux-gnueabihf/5.3.1/include)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//lib/gcc/arm-linux-gnueabihf/5.3.1/include-fixed)%" + cxx_builtin_include_directory: "%package(@org_linaro_components_toolchain_gcc_5_3_1//arm-linux-gnueabihf/include)%/c++/5.3.1" + + linker_flag: "--sysroot=external/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc" + linker_flag: "-lstdc++" + linker_flag: "-latomic" + linker_flag: "-lm" + linker_flag: "-lpthread" + linker_flag: "-Ltools/arm_compiler/linaro_linux_gcc/clang_more_libs" + linker_flag: "-Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/lib" + linker_flag: "-Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/lib" + linker_flag: "-Lexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/libc/usr/lib" + linker_flag: "-Bexternal/org_linaro_components_toolchain_gcc_5_3_1/arm-linux-gnueabihf/bin" + linker_flag: "-Wl,--dynamic-linker=/lib/ld-linux-armhf.so.3" + + # Anticipated future default. + # This makes GCC and Clang do what we want when called through symlinks. + unfiltered_cxx_flag: "-no-canonical-prefixes" + linker_flag: "-no-canonical-prefixes" + + # Make C++ compilation deterministic. Use linkstamping instead of these + # compiler symbols. + unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" + unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" + unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" + unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" + + # Security hardening on by default. + # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. + # We need to undef it before redefining it as some distributions now have + # it enabled by default. + compiler_flag: "-U_FORTIFY_SOURCE" + compiler_flag: "-fstack-protector" + compiler_flag: "-fPIE" + linker_flag: "-pie" + linker_flag: "-Wl,-z,relro,-z,now" + + # Enable coloring even if there's no attached terminal. Bazel removes the + # escape sequences if --nocolor is specified. + compiler_flag: "-fdiagnostics-color=always" + + # All warnings are enabled. Maybe enable -Werror as well? + compiler_flag: "-Wall" + # Enable a few more warnings that aren't part of -Wall. + compiler_flag: "-Wunused-but-set-parameter" + # But disable some that are problematic. + compiler_flag: "-Wno-free-nonheap-object" # has false positives + + # Keep stack frames for debugging, even in opt mode. + compiler_flag: "-fno-omit-frame-pointer" + + compilation_mode_flags { + mode: DBG + # Enable debug symbols. + compiler_flag: "-g" + } + compilation_mode_flags { + mode: OPT + # No debug symbols. + # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or + # even generally? However, that can't happen here, as it requires special + # handling in Bazel. + compiler_flag: "-g0" + + # Conservative choice for -O + # -O3 can increase binary size and even slow down the resulting binaries. + # Profile first and / or use FDO if you need better performance than this. + compiler_flag: "-O2" + + # Disable assertions + compiler_flag: "-DNDEBUG" + + # Removal of unused code and data at link time (can this increase binary size in some cases?). + compiler_flag: "-ffunction-sections" + compiler_flag: "-fdata-sections" + linker_flag: "-Wl,--gc-sections" + } +} + +toolchain { + toolchain_identifier: "local" + abi_libc_version: "local" + abi_version: "local" + builtin_sysroot: "" + compiler: "compiler" + compiler_flag: "-U_FORTIFY_SOURCE" + compiler_flag: "-D_FORTIFY_SOURCE=2" + compiler_flag: "-fstack-protector" + compiler_flag: "-Wall" + compiler_flag: "-Wl,-z,-relro,-z,now" + compiler_flag: "-Wunused-but-set-parameter" + compiler_flag: "-Wno-free-nonheap-object" + compiler_flag: "-fno-omit-frame-pointer" + cxx_builtin_include_directory: "/usr/include/c++/4.8" + cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu/c++/4.8" + cxx_builtin_include_directory: "/usr/include/c++/4.8/backward" + cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/4.8/include" + cxx_builtin_include_directory: "/usr/local/include" + cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed" + cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu" + cxx_builtin_include_directory: "/usr/include" + cxx_flag: "-std=c++0x" + host_system_name: "local" + linker_flag: "-lstdc++" + linker_flag: "-lm" + linker_flag: "-Wl,-no-as-needed" + linker_flag: "-pass-exit-codes" + needsPic: true + objcopy_embed_flag: "-I" + objcopy_embed_flag: "binary" + supports_fission: false + supports_gold_linker: false + supports_incremental_linker: false + supports_interface_shared_objects: false + supports_normalizing_ar: false + supports_start_end_lib: false + supports_thin_archives: false + target_cpu: "k8" + target_libc: "local" + target_system_name: "local" + unfiltered_cxx_flag: "-fno-canonical-system-headers" + unfiltered_cxx_flag: "-Wno-builtin-macro-redefined" + unfiltered_cxx_flag: "-D__DATE__=\"redacted\"" + unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\"" + unfiltered_cxx_flag: "-D__TIME__=\"redacted\"" + tool_path {name: "ar" path: "/usr/bin/ar" } + 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" } + + compilation_mode_flags { + mode: DBG + compiler_flag: "-g" + } + compilation_mode_flags { + mode: OPT + compiler_flag: "-g0" + compiler_flag: "-O2" + compiler_flag: "-DNDEBUG" + compiler_flag: "-ffunction-sections" + compiler_flag: "-fdata-sections" + linker_flag: "-Wl,--gc-sections" + } + linking_mode_flags { mode: DYNAMIC } +} diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/BUILD b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/BUILD new file mode 100755 index 00000000..eb686e88 --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/BUILD @@ -0,0 +1,85 @@ +package(default_visibility = ["//tools/arm_compiler:__pkg__"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = ["//src/test/shell/bazel/testdata/bazel_toolchain_test_data/tools/arm_compiler:__pkg__"], +) + +filegroup( + name = "gcc", + srcs = [ + "arm-linux-gnueabihf-gcc", + "@org_linaro_components_toolchain_gcc_5_3_1//:gcc", + ], +) + +filegroup( + name = "ar", + srcs = [ + "arm-linux-gnueabihf-ar", + "@org_linaro_components_toolchain_gcc_5_3_1//:ar", + ], +) + +filegroup( + name = "ld", + srcs = [ + "arm-linux-gnueabihf-ld", + "@org_linaro_components_toolchain_gcc_5_3_1//:ld", + ], +) + +filegroup( + name = "nm", + srcs = [ + "arm-linux-gnueabihf-nm", + "@org_linaro_components_toolchain_gcc_5_3_1//:nm", + ], +) + +filegroup( + name = "objcopy", + srcs = [ + "arm-linux-gnueabihf-objcopy", + "@org_linaro_components_toolchain_gcc_5_3_1//:objcopy", + ], +) + +filegroup( + name = "objdump", + srcs = [ + "arm-linux-gnueabihf-objdump", + "@org_linaro_components_toolchain_gcc_5_3_1//:objdump", + ], +) + +filegroup( + name = "strip", + srcs = [ + "arm-linux-gnueabihf-strip", + "@org_linaro_components_toolchain_gcc_5_3_1//:strip", + ], +) + +filegroup( + name = "as", + srcs = [ + "arm-linux-gnueabihf-as", + "@org_linaro_components_toolchain_gcc_5_3_1//:as", + ], +) + +filegroup( + name = "tool-wrappers", + srcs = [ + ":ar", + ":as", + ":gcc", + ":ld", + ":nm", + ":objcopy", + ":objdump", + ":strip", + ], +) diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ar b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ar new file mode 100755 index 00000000..f5eef7ad --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ar @@ -0,0 +1,11 @@ +#!/bin/bash --norc + +if [[ -z "${EXT_BUILD_ROOT}" ]]; then + MY_PREFIX="" +else + MY_PREFIX="${EXT_BUILD_ROOT}/" +fi + +exec -a arm-linux-gnueabihf-ar \ + ${MY_PREFIX}external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-ar \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-as b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-as new file mode 100755 index 00000000..7738e76f --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-as @@ -0,0 +1,5 @@ +#!/bin/bash --norc + +exec -a arm-linux-gnueabihf-as \ + external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-as \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc new file mode 100755 index 00000000..77a092a4 --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc @@ -0,0 +1,12 @@ +#!/bin/bash --norc + +if [[ -z "${EXT_BUILD_ROOT}" ]]; then + MY_PREFIX="" +else + MY_PREFIX="${EXT_BUILD_ROOT}/" +fi + +PATH="${MY_PREFIX}external/org_linaro_components_toolchain_gcc_5_3_1/libexec/gcc/arm-linux-gnueabihf/4.9.3:$PATH" \ + exec \ + ${MY_PREFIX}external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-gcc \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ld b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ld new file mode 100755 index 00000000..b56a1c1a --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ld @@ -0,0 +1,5 @@ +#!/bin/bash --norc + +exec -a arm-linux-gnueabihf-ld \ + external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-ld \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-nm b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-nm new file mode 100755 index 00000000..c802e5bf --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-nm @@ -0,0 +1,5 @@ +#!/bin/bash --norc + +exec -a arm-linux-gnueabihf-nm \ + external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-nm \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objcopy b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objcopy new file mode 100755 index 00000000..503184b9 --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objcopy @@ -0,0 +1,5 @@ +#!/bin/bash --norc + +exec -a arm-linux-gnueabihf-objcopy \ + external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-objcopy \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objdump b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objdump new file mode 100755 index 00000000..5c9667a9 --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objdump @@ -0,0 +1,5 @@ +#!/bin/bash --norc + +exec -a arm-linux-gnueabihf-objdump \ + external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-objdump \ + "$@" diff --git a/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-strip b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-strip new file mode 100755 index 00000000..9e71cbfe --- /dev/null +++ b/examples/cmake_crosstool/tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-strip @@ -0,0 +1,5 @@ +#!/bin/bash --norc + +exec -a arm-linux-gnueabihf-strip \ + external/org_linaro_components_toolchain_gcc_5_3_1/bin/arm-linux-gnueabihf-strip \ + "$@" diff --git a/test/cmake_text_tests.bzl b/test/cmake_text_tests.bzl index ccf688e2..f7ad6f78 100644 --- a/test/cmake_text_tests.bzl +++ b/test/cmake_text_tests.bzl @@ -73,9 +73,9 @@ def _fill_crossfile_from_toolchain_test(ctx): env = unittest.begin(ctx) tools = CxxToolsInfo( - cc = "some-cc-value", + cc = "/some-cc-value", cxx = "external/cxx-value", - cxx_linker_static = "cxx_linker_static", + cxx_linker_static = "/cxx_linker_static", cxx_linker_executable = "ws/cxx_linker_executable", ) flags = CxxFlagsInfo( @@ -97,9 +97,9 @@ def _fill_crossfile_from_toolchain_test(ctx): "CMAKE_SYSROOT": "/abc/sysroot", "CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN": "cc-toolchain", "CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN": "cxx-toolchain", - "CMAKE_C_COMPILER": "some-cc-value", + "CMAKE_C_COMPILER": "/some-cc-value", "CMAKE_CXX_COMPILER": "$EXT_BUILD_ROOT/external/cxx-value", - "CMAKE_AR": "cxx_linker_static", + "CMAKE_AR": "/cxx_linker_static", "CMAKE_CXX_LINK_EXECUTABLE": "$EXT_BUILD_ROOT/ws/cxx_linker_executable -o ", "CMAKE_C_FLAGS_INIT": "-cc-flag -gcc_toolchain cc-toolchain", "CMAKE_CXX_FLAGS_INIT": "--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain", @@ -311,9 +311,9 @@ def _create_cmake_script_no_toolchain_file_test(ctx): env = unittest.begin(ctx) tools = CxxToolsInfo( - cc = "some-cc-value", + cc = "/some-cc-value", cxx = "external/cxx-value", - cxx_linker_static = "cxx_linker_static", + cxx_linker_static = "/cxx_linker_static", cxx_linker_executable = "ws/cxx_linker_executable", ) flags = CxxFlagsInfo( @@ -340,7 +340,7 @@ def _create_cmake_script_no_toolchain_file_test(ctx): os_info = OSInfo(is_unix = True, is_osx = False, is_win = False) script = create_cmake_script("ws", os_info, tools, flags, "test_rule", "external/test_rule", True, user_cache, user_env, ["-GNinja"]) - expected = "CC=\"sink-cc-value\" CXX=\"sink-cxx-value\" CFLAGS=\"-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag\" CXXFLAGS=\"--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain\" ASMFLAGS=\"assemble assemble-user\" CUSTOM_ENV=\"YES\" {cmake} -DCMAKE_AR=\"cxx_linker_static\" -DCMAKE_CXX_LINK_EXECUTABLE=\"became\" -DCMAKE_SHARED_LINKER_FLAGS=\"shared1 shared2\" -DCMAKE_EXE_LINKER_FLAGS=\"executable\" -DCUSTOM_CACHE=\"YES\" -DCMAKE_BUILD_TYPE=\"user_type\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -GNinja $EXT_BUILD_ROOT/external/test_rule" + expected = "CC=\"sink-cc-value\" CXX=\"sink-cxx-value\" CFLAGS=\"-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag\" CXXFLAGS=\"--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain\" ASMFLAGS=\"assemble assemble-user\" CUSTOM_ENV=\"YES\" {cmake} -DCMAKE_AR=\"/cxx_linker_static\" -DCMAKE_CXX_LINK_EXECUTABLE=\"became\" -DCMAKE_SHARED_LINKER_FLAGS=\"shared1 shared2\" -DCMAKE_EXE_LINKER_FLAGS=\"executable\" -DCUSTOM_CACHE=\"YES\" -DCMAKE_BUILD_TYPE=\"user_type\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -GNinja $EXT_BUILD_ROOT/external/test_rule" asserts.equals(env, expected.format(cmake = CMAKE_COMMAND), script) unittest.end(env) @@ -351,7 +351,7 @@ def _create_cmake_script_toolchain_file_test(ctx): tools = CxxToolsInfo( cc = "some-cc-value", cxx = "external/cxx-value", - cxx_linker_static = "cxx_linker_static", + cxx_linker_static = "/cxx_linker_static", cxx_linker_executable = "ws/cxx_linker_executable", ) flags = CxxFlagsInfo( @@ -384,7 +384,7 @@ set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "cc-toolchain") set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "cxx-toolchain") set(CMAKE_C_COMPILER "sink-cc-value") set(CMAKE_CXX_COMPILER "sink-cxx-value") -set(CMAKE_AR "cxx_linker_static" CACHE FILEPATH "Archiver") +set(CMAKE_AR "/cxx_linker_static" CACHE FILEPATH "Archiver") set(CMAKE_CXX_LINK_EXECUTABLE "became") set(CMAKE_C_FLAGS_INIT "-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag") set(CMAKE_CXX_FLAGS_INIT "--quoted=\\\"abc def\\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain") diff --git a/tools/build_defs/cmake_script.bzl b/tools/build_defs/cmake_script.bzl index bd6214c1..b9c411eb 100644 --- a/tools/build_defs/cmake_script.bzl +++ b/tools/build_defs/cmake_script.bzl @@ -197,13 +197,14 @@ def _fill_crossfile_from_toolchain(workspace_name, target_os, tools, flags): if _ext_toolchain_cxx: dict["CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN"] = _absolutize(workspace_name, _ext_toolchain_cxx) + # Force convert tools paths to absolute using $EXT_BUILD_ROOT if tools.cc: - dict["CMAKE_C_COMPILER"] = _absolutize(workspace_name, tools.cc) + dict["CMAKE_C_COMPILER"] = _absolutize(workspace_name, tools.cc, True) if tools.cxx: - dict["CMAKE_CXX_COMPILER"] = _absolutize(workspace_name, tools.cxx) + dict["CMAKE_CXX_COMPILER"] = _absolutize(workspace_name, tools.cxx, True) if tools.cxx_linker_static: - dict["CMAKE_AR"] = _absolutize(workspace_name, tools.cxx_linker_static) + dict["CMAKE_AR"] = _absolutize(workspace_name, tools.cxx_linker_static, True) if tools.cxx_linker_executable and tools.cxx_linker_executable != tools.cxx: normalized_path = _absolutize(workspace_name, tools.cxx_linker_executable) @@ -261,8 +262,8 @@ def _tail_if_starts_with(str, start): return str[len(start):] return None -def _absolutize(workspace_name, text): - return absolutize_path_in_str(workspace_name, "$EXT_BUILD_ROOT/", text) +def _absolutize(workspace_name, text, force = False): + return absolutize_path_in_str(workspace_name, "$EXT_BUILD_ROOT/", text, force) def _join_flags_list(workspace_name, flags): return " ".join([_absolutize(workspace_name, flag) for flag in flags]) diff --git a/tools/build_defs/new_11_2018/cc_toolchain_util.bzl b/tools/build_defs/new_11_2018/cc_toolchain_util.bzl index e4dbd337..95b1ec3f 100644 --- a/tools/build_defs/new_11_2018/cc_toolchain_util.bzl +++ b/tools/build_defs/new_11_2018/cc_toolchain_util.bzl @@ -334,7 +334,7 @@ def get_flags_info(ctx): ), ) -def absolutize_path_in_str(workspace_name, root_str, text): +def absolutize_path_in_str(workspace_name, root_str, text, force = False): """ Replaces relative paths in [the middle of] 'text', prepending them with 'root_str'. If there is nothing to replace, returns the 'text'. @@ -350,6 +350,10 @@ def absolutize_path_in_str(workspace_name, root_str, text): new_text = _prefix(text, "external/", root_str) if new_text == text: new_text = _prefix(text, workspace_name + "/", root_str) + # absolutize relative by adding our working directory + # this works because we ru on windows under msys now + if force and new_text == text and not text.startswith("/"): + new_text = root_str + "/" + text return new_text diff --git a/tools/build_defs/new_11_2018/framework.bzl b/tools/build_defs/new_11_2018/framework.bzl index af34cb07..812b51b7 100644 --- a/tools/build_defs/new_11_2018/framework.bzl +++ b/tools/build_defs/new_11_2018/framework.bzl @@ -260,6 +260,7 @@ def cc_external_rule_impl(ctx, attrs): "set -e", "source " + shell_utils, "\n".join(define_variables), + "path $EXT_BUILD_ROOT", "\n".join(trap_function), "mkdir -p $EXT_BUILD_DEPS", "mkdir -p $INSTALLDIR", diff --git a/tools/build_defs/old_10_2018/cc_toolchain_util.bzl b/tools/build_defs/old_10_2018/cc_toolchain_util.bzl index 6dd4fb64..55281c4d 100644 --- a/tools/build_defs/old_10_2018/cc_toolchain_util.bzl +++ b/tools/build_defs/old_10_2018/cc_toolchain_util.bzl @@ -394,7 +394,7 @@ def get_flags_info(ctx): ), ) -def absolutize_path_in_str(workspace_name, root_str, text): +def absolutize_path_in_str(workspace_name, root_str, text, force = False): """ Replaces relative paths in [the middle of] 'text', prepending them with 'root_str'. If there is nothing to replace, returns the 'text'. @@ -410,6 +410,10 @@ def absolutize_path_in_str(workspace_name, root_str, text): new_text = _prefix(text, "external/", root_str) if new_text == text: new_text = _prefix(text, workspace_name + "/", root_str) + # absolutize relative by adding our working directory + # this works because we ru on windows under msys now + if force and new_text == text and not text.startswith("/"): + new_text = root_str + "/" + text return new_text diff --git a/tools/build_defs/old_10_2018/framework.bzl b/tools/build_defs/old_10_2018/framework.bzl index e3290daf..f7633bee 100644 --- a/tools/build_defs/old_10_2018/framework.bzl +++ b/tools/build_defs/old_10_2018/framework.bzl @@ -260,6 +260,7 @@ def cc_external_rule_impl(ctx, attrs): "set -e", "source " + shell_utils, "\n".join(define_variables), + "path $EXT_BUILD_ROOT", "\n".join(trap_function), "mkdir -p $EXT_BUILD_DEPS", "mkdir -p $INSTALLDIR", diff --git a/tools/build_defs/old_11_2018/cc_toolchain_util.bzl b/tools/build_defs/old_11_2018/cc_toolchain_util.bzl index 3b523141..62f03a08 100644 --- a/tools/build_defs/old_11_2018/cc_toolchain_util.bzl +++ b/tools/build_defs/old_11_2018/cc_toolchain_util.bzl @@ -394,7 +394,7 @@ def get_flags_info(ctx): ), ) -def absolutize_path_in_str(workspace_name, root_str, text): +def absolutize_path_in_str(workspace_name, root_str, text, force = False): """ Replaces relative paths in [the middle of] 'text', prepending them with 'root_str'. If there is nothing to replace, returns the 'text'. @@ -410,6 +410,10 @@ def absolutize_path_in_str(workspace_name, root_str, text): new_text = _prefix(text, "external/", root_str) if new_text == text: new_text = _prefix(text, workspace_name + "/", root_str) + # absolutize relative by adding our working directory + # this works because we run on windows under msys now + if force and new_text == text and not text.startswith("/"): + new_text = root_str + "/" + text return new_text diff --git a/tools/build_defs/old_11_2018/framework.bzl b/tools/build_defs/old_11_2018/framework.bzl index 12834fed..0a74a38a 100644 --- a/tools/build_defs/old_11_2018/framework.bzl +++ b/tools/build_defs/old_11_2018/framework.bzl @@ -260,6 +260,7 @@ def cc_external_rule_impl(ctx, attrs): "set -e", "source " + shell_utils, "\n".join(define_variables), + "path $EXT_BUILD_ROOT", "\n".join(trap_function), "mkdir -p $EXT_BUILD_DEPS", "mkdir -p $INSTALLDIR",