Added "targets" API (#556)
* Added `targets` API to all existing build rules * Updated examples * Restore making the make toolchain always available. * Add support for generator cmake parsing and setting CMAKE_MAKE_PROGRAM * Cleaned up duplicate generator arguments * Fixed cmake tests * Updated docs * Addressed PR feedback * Fixed missing and incorrect generators * Fixed `generate_args` name
This commit is contained in:
parent
eae19778d5
commit
e4399415b8
18
README.md
18
README.md
|
@ -31,7 +31,7 @@ These rules are now maintained by the community.
|
|||
|
||||
- Added native ninja build rule
|
||||
|
||||
- Now builds under the bazel sandbox rather than in /tmp
|
||||
- Now builds under the Bazel sandbox rather than in `/tmp`
|
||||
|
||||
- Tidied up the structure of the examples directory
|
||||
|
||||
|
@ -41,7 +41,7 @@ These rules are now maintained by the community.
|
|||
|
||||
**March 2019:**
|
||||
|
||||
- Support for versions earlier then 0.22 was removed.
|
||||
- Support for versions earlier than 0.22 was removed.
|
||||
|
||||
- Tests on Bazel CI are running in the nested workspace
|
||||
|
||||
|
@ -49,7 +49,7 @@ These rules are now maintained by the community.
|
|||
|
||||
- Bazel 0.22.0 is released, no flags are needed for this version, but it does not work on Windows (Bazel C++ API is broken).
|
||||
|
||||
- Support for versions earlier then 0.20 was removed.
|
||||
- Support for versions earlier than 0.20 was removed.
|
||||
|
||||
- [rules_foreign_cc take-aways](https://docs.google.com/document/d/1ZVvzvkUVTkPCzI-2z4S4VrSNu4kdaBknz7UnK8vaoZU/edit?usp=sharing) describing the recent work has been published.
|
||||
|
||||
|
@ -177,8 +177,6 @@ cmake(
|
|||
# This option can be omitted
|
||||
cmake_options = ["-G \"Visual Studio 15 2017 Win64\""],
|
||||
lib_source = ":srcs",
|
||||
# .vcxproj or .sln file must be specified argument, as multiple files are generated by CMake
|
||||
make_commands = ["MSBuild.exe INSTALL.vcxproj"],
|
||||
)
|
||||
|
||||
cmake(
|
||||
|
@ -188,11 +186,6 @@ cmake(
|
|||
# explicitly specify the generator
|
||||
cmake_options = ["-GNinja"],
|
||||
lib_source = ":srcs",
|
||||
# specify to call ninja after configuring
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
)
|
||||
|
||||
cmake(
|
||||
|
@ -200,11 +193,6 @@ cmake(
|
|||
# explicitly specify the generator
|
||||
cmake_options = ["-G \"NMake Makefiles\""],
|
||||
lib_source = ":srcs",
|
||||
# specify to call nmake after configuring
|
||||
make_commands = [
|
||||
"nmake",
|
||||
"nmake install",
|
||||
],
|
||||
# expect to find ./lib/hello.lib as the result of the build
|
||||
out_static_libs = ["hello.lib"]
|
||||
)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<pre>
|
||||
boost_build(<a href="#boost_build-name">name</a>, <a href="#boost_build-additional_inputs">additional_inputs</a>, <a href="#boost_build-additional_tools">additional_tools</a>, <a href="#boost_build-alwayslink">alwayslink</a>, <a href="#boost_build-binaries">binaries</a>, <a href="#boost_build-bootstrap_options">bootstrap_options</a>,
|
||||
<a href="#boost_build-data">data</a>, <a href="#boost_build-defines">defines</a>, <a href="#boost_build-deps">deps</a>, <a href="#boost_build-env">env</a>, <a href="#boost_build-headers_only">headers_only</a>, <a href="#boost_build-interface_libraries">interface_libraries</a>, <a href="#boost_build-lib_name">lib_name</a>, <a href="#boost_build-lib_source">lib_source</a>,
|
||||
<a href="#boost_build-linkopts">linkopts</a>, <a href="#boost_build-make_commands">make_commands</a>, <a href="#boost_build-out_bin_dir">out_bin_dir</a>, <a href="#boost_build-out_binaries">out_binaries</a>, <a href="#boost_build-out_headers_only">out_headers_only</a>, <a href="#boost_build-out_include_dir">out_include_dir</a>,
|
||||
<a href="#boost_build-linkopts">linkopts</a>, <a href="#boost_build-out_bin_dir">out_bin_dir</a>, <a href="#boost_build-out_binaries">out_binaries</a>, <a href="#boost_build-out_headers_only">out_headers_only</a>, <a href="#boost_build-out_include_dir">out_include_dir</a>,
|
||||
<a href="#boost_build-out_interface_libs">out_interface_libs</a>, <a href="#boost_build-out_lib_dir">out_lib_dir</a>, <a href="#boost_build-out_shared_libs">out_shared_libs</a>, <a href="#boost_build-out_static_libs">out_static_libs</a>, <a href="#boost_build-postfix_script">postfix_script</a>,
|
||||
<a href="#boost_build-shared_libraries">shared_libraries</a>, <a href="#boost_build-static_libraries">static_libraries</a>, <a href="#boost_build-tools_deps">tools_deps</a>, <a href="#boost_build-user_options">user_options</a>)
|
||||
</pre>
|
||||
|
@ -48,7 +48,6 @@ Rule for building Boost. Invokes bootstrap.sh and then b2 install.
|
|||
| <a id="boost_build-lib_name"></a>lib_name | Library name. Defines the name of the install directory and the name of the static library, if no output files parameters are defined (any of static_libraries, shared_libraries, interface_libraries, binaries_names) Optional. If not defined, defaults to the target's name. | String | optional | "" |
|
||||
| <a id="boost_build-lib_source"></a>lib_source | Label with source code to build. Typically a filegroup for the source of remote repository. Mandatory. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
| <a id="boost_build-linkopts"></a>linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] |
|
||||
| <a id="boost_build-make_commands"></a>make_commands | Optinal make commands, defaults to ["make", "make install"] | List of strings | optional | ["make", "make install"] |
|
||||
| <a id="boost_build-out_bin_dir"></a>out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" |
|
||||
| <a id="boost_build-out_binaries"></a>out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] |
|
||||
| <a id="boost_build-out_headers_only"></a>out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False |
|
||||
|
@ -69,12 +68,12 @@ Rule for building Boost. Invokes bootstrap.sh and then b2 install.
|
|||
## cmake
|
||||
|
||||
<pre>
|
||||
cmake(<a href="#cmake-name">name</a>, <a href="#cmake-additional_inputs">additional_inputs</a>, <a href="#cmake-additional_tools">additional_tools</a>, <a href="#cmake-alwayslink">alwayslink</a>, <a href="#cmake-binaries">binaries</a>, <a href="#cmake-cache_entries">cache_entries</a>, <a href="#cmake-cmake_options">cmake_options</a>,
|
||||
<a href="#cmake-data">data</a>, <a href="#cmake-defines">defines</a>, <a href="#cmake-deps">deps</a>, <a href="#cmake-env">env</a>, <a href="#cmake-env_vars">env_vars</a>, <a href="#cmake-generate_crosstool_file">generate_crosstool_file</a>, <a href="#cmake-headers_only">headers_only</a>, <a href="#cmake-install_prefix">install_prefix</a>,
|
||||
<a href="#cmake-interface_libraries">interface_libraries</a>, <a href="#cmake-lib_name">lib_name</a>, <a href="#cmake-lib_source">lib_source</a>, <a href="#cmake-linkopts">linkopts</a>, <a href="#cmake-make_commands">make_commands</a>, <a href="#cmake-out_bin_dir">out_bin_dir</a>, <a href="#cmake-out_binaries">out_binaries</a>,
|
||||
<a href="#cmake-out_headers_only">out_headers_only</a>, <a href="#cmake-out_include_dir">out_include_dir</a>, <a href="#cmake-out_interface_libs">out_interface_libs</a>, <a href="#cmake-out_lib_dir">out_lib_dir</a>, <a href="#cmake-out_shared_libs">out_shared_libs</a>,
|
||||
<a href="#cmake-out_static_libs">out_static_libs</a>, <a href="#cmake-postfix_script">postfix_script</a>, <a href="#cmake-shared_libraries">shared_libraries</a>, <a href="#cmake-static_libraries">static_libraries</a>, <a href="#cmake-tools_deps">tools_deps</a>,
|
||||
<a href="#cmake-working_directory">working_directory</a>)
|
||||
cmake(<a href="#cmake-name">name</a>, <a href="#cmake-additional_inputs">additional_inputs</a>, <a href="#cmake-additional_tools">additional_tools</a>, <a href="#cmake-alwayslink">alwayslink</a>, <a href="#cmake-binaries">binaries</a>, <a href="#cmake-build_args">build_args</a>, <a href="#cmake-cache_entries">cache_entries</a>,
|
||||
<a href="#cmake-cmake_options">cmake_options</a>, <a href="#cmake-data">data</a>, <a href="#cmake-defines">defines</a>, <a href="#cmake-deps">deps</a>, <a href="#cmake-env">env</a>, <a href="#cmake-env_vars">env_vars</a>, <a href="#cmake-generate_args">generate_args</a>, <a href="#cmake-generate_crosstool_file">generate_crosstool_file</a>,
|
||||
<a href="#cmake-headers_only">headers_only</a>, <a href="#cmake-install">install</a>, <a href="#cmake-install_args">install_args</a>, <a href="#cmake-install_prefix">install_prefix</a>, <a href="#cmake-interface_libraries">interface_libraries</a>, <a href="#cmake-lib_name">lib_name</a>, <a href="#cmake-lib_source">lib_source</a>,
|
||||
<a href="#cmake-linkopts">linkopts</a>, <a href="#cmake-make_commands">make_commands</a>, <a href="#cmake-out_bin_dir">out_bin_dir</a>, <a href="#cmake-out_binaries">out_binaries</a>, <a href="#cmake-out_headers_only">out_headers_only</a>, <a href="#cmake-out_include_dir">out_include_dir</a>,
|
||||
<a href="#cmake-out_interface_libs">out_interface_libs</a>, <a href="#cmake-out_lib_dir">out_lib_dir</a>, <a href="#cmake-out_shared_libs">out_shared_libs</a>, <a href="#cmake-out_static_libs">out_static_libs</a>, <a href="#cmake-postfix_script">postfix_script</a>,
|
||||
<a href="#cmake-shared_libraries">shared_libraries</a>, <a href="#cmake-static_libraries">static_libraries</a>, <a href="#cmake-targets">targets</a>, <a href="#cmake-tools_deps">tools_deps</a>, <a href="#cmake-working_directory">working_directory</a>)
|
||||
</pre>
|
||||
|
||||
Rule for building external library with CMake.
|
||||
|
@ -89,21 +88,25 @@ Rule for building external library with CMake.
|
|||
| <a id="cmake-additional_tools"></a>additional_tools | Optional additional tools needed for the building. Not used by the shell script part in cc_external_rule_impl. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="cmake-alwayslink"></a>alwayslink | Optional. if true, link all the object files from the static library, even if they are not used. | Boolean | optional | False |
|
||||
| <a id="cmake-binaries"></a>binaries | __deprecated__: Use <code>out_binaries</code> instead. | List of strings | optional | [] |
|
||||
| <a id="cmake-cache_entries"></a>cache_entries | CMake cache entries to initialize (they will be passed with -Dkey=value) Values, defined by the toolchain, will be joined with the values, passed here. (Toolchain values come first) | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="cmake-cmake_options"></a>cmake_options | Other CMake options | List of strings | optional | [] |
|
||||
| <a id="cmake-build_args"></a>build_args | Arguments for the CMake build command | List of strings | optional | [] |
|
||||
| <a id="cmake-cache_entries"></a>cache_entries | CMake cache entries to initialize (they will be passed with <code>-Dkey=value</code>) Values, defined by the toolchain, will be joined with the values, passed here. (Toolchain values come first) | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="cmake-cmake_options"></a>cmake_options | __deprecated__: Use <code>generate_args</code> | List of strings | optional | [] |
|
||||
| <a id="cmake-data"></a>data | Files needed by this rule at runtime. May list file or rule targets. Generally allows any target. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="cmake-defines"></a>defines | Optional compilation definitions to be passed to the dependencies of this library. They are NOT passed to the compiler, you should duplicate them in the configuration options. | List of strings | optional | [] |
|
||||
| <a id="cmake-deps"></a>deps | Optional dependencies to be copied into the directory structure. Typically those directly required for the external building of the library/binaries. (i.e. those that the external buidl system will be looking for and paths to which are provided by the calling rule) | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="cmake-env"></a>env | Environment variables to set during the build. $(execpath) macros may be used to point at files which are listed as data deps, tools_deps, or additional_tools, but unlike with other rules, these will be replaced with absolute paths to those files, because the build does not run in the exec root. No other macros are supported. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="cmake-env_vars"></a>env_vars | CMake environment variable values to join with toolchain-defined. For example, additional CXXFLAGS. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="cmake-generate_crosstool_file"></a>generate_crosstool_file | When True, CMake crosstool file will be generated from the toolchain values, provided cache-entries and env_vars (some values will still be passed as -Dkey=value and environment variables). If CMAKE_TOOLCHAIN_FILE cache entry is passed, specified crosstool file will be used When using this option to cross-compile, it is required to specify CMAKE_SYSTEM_NAME in the cache_entries | Boolean | optional | True |
|
||||
| <a id="cmake-env_vars"></a>env_vars | CMake environment variable values to join with toolchain-defined. For example, additional <code>CXXFLAGS</code>. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="cmake-generate_args"></a>generate_args | Arguments for CMake's generate command. Arguments should be passed as key/value pairs. eg: <code>["-G Ninja", "--debug-output", "-DFOO=bar"]</code>. | List of strings | optional | [] |
|
||||
| <a id="cmake-generate_crosstool_file"></a>generate_crosstool_file | When True, CMake crosstool file will be generated from the toolchain values, provided cache-entries and env_vars (some values will still be passed as <code>-Dkey=value</code> and environment variables). If <code>CMAKE_TOOLCHAIN_FILE</code> cache entry is passed, specified crosstool file will be used When using this option to cross-compile, it is required to specify <code>CMAKE_SYSTEM_NAME</code> in the cache_entries | Boolean | optional | True |
|
||||
| <a id="cmake-headers_only"></a>headers_only | __deprecated__: Use <code>out_headers_only</code> instead. | Boolean | optional | False |
|
||||
| <a id="cmake-install_prefix"></a>install_prefix | Relative install prefix to be passed to CMake in -DCMAKE_INSTALL_PREFIX | String | optional | "" |
|
||||
| <a id="cmake-install"></a>install | If True, the <code>cmake --install</code> comand will be performed after a build | Boolean | optional | True |
|
||||
| <a id="cmake-install_args"></a>install_args | Arguments for the CMake install command | List of strings | optional | [] |
|
||||
| <a id="cmake-install_prefix"></a>install_prefix | Relative install prefix to be passed to CMake in <code>-DCMAKE_INSTALL_PREFIX</code> | String | optional | "" |
|
||||
| <a id="cmake-interface_libraries"></a>interface_libraries | __deprecated__: Use <code>out_interface_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="cmake-lib_name"></a>lib_name | Library name. Defines the name of the install directory and the name of the static library, if no output files parameters are defined (any of static_libraries, shared_libraries, interface_libraries, binaries_names) Optional. If not defined, defaults to the target's name. | String | optional | "" |
|
||||
| <a id="cmake-lib_source"></a>lib_source | Label with source code to build. Typically a filegroup for the source of remote repository. Mandatory. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
| <a id="cmake-linkopts"></a>linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] |
|
||||
| <a id="cmake-make_commands"></a>make_commands | Optinal make commands, defaults to ["make", "make install"] | List of strings | optional | ["make", "make install"] |
|
||||
| <a id="cmake-make_commands"></a>make_commands | __deprecated__: Optional hard coded commands to replace the <code>cmake --build</code> commands. It's recommended to leave this empty and use the <code>targets</code> + <code>build_args</code> attributes. | List of strings | optional | [] |
|
||||
| <a id="cmake-out_bin_dir"></a>out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" |
|
||||
| <a id="cmake-out_binaries"></a>out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] |
|
||||
| <a id="cmake-out_headers_only"></a>out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False |
|
||||
|
@ -115,6 +118,7 @@ Rule for building external library with CMake.
|
|||
| <a id="cmake-postfix_script"></a>postfix_script | Optional part of the shell script to be added after the make commands | String | optional | "" |
|
||||
| <a id="cmake-shared_libraries"></a>shared_libraries | __deprecated__: Use <code>out_shared_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="cmake-static_libraries"></a>static_libraries | __deprecated__: Use <code>out_static_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="cmake-targets"></a>targets | A list of targets with in the foreign build system to produce. An empty string (<code>""</code>) will result in a call to the underlying build system with no explicit target set | List of strings | optional | [] |
|
||||
| <a id="cmake-tools_deps"></a>tools_deps | Optional tools to be copied into the directory structure. Similar to deps, those directly required for the external building of the library/binaries. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="cmake-working_directory"></a>working_directory | Working directory, with the main CMakeLists.txt (otherwise, the top directory of the lib_source label files is used.) | String | optional | "" |
|
||||
|
||||
|
@ -124,7 +128,7 @@ Rule for building external library with CMake.
|
|||
## cmake_tool
|
||||
|
||||
<pre>
|
||||
cmake_tool(<a href="#cmake_tool-name">name</a>, <a href="#cmake_tool-cmake_srcs">cmake_srcs</a>)
|
||||
cmake_tool(<a href="#cmake_tool-name">name</a>, <a href="#cmake_tool-srcs">srcs</a>)
|
||||
</pre>
|
||||
|
||||
Rule for building CMake. Invokes bootstrap script and make install.
|
||||
|
@ -135,7 +139,7 @@ Rule for building CMake. Invokes bootstrap script and make install.
|
|||
| Name | Description | Type | Mandatory | Default |
|
||||
| :------------- | :------------- | :------------- | :------------- | :------------- |
|
||||
| <a id="cmake_tool-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|
||||
| <a id="cmake_tool-cmake_srcs"></a>cmake_srcs | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
| <a id="cmake_tool-srcs"></a>srcs | The target containing the build tool's sources | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
|
||||
|
||||
<a id="#configure_make"></a>
|
||||
|
@ -143,14 +147,14 @@ Rule for building CMake. Invokes bootstrap script and make install.
|
|||
## configure_make
|
||||
|
||||
<pre>
|
||||
configure_make(<a href="#configure_make-name">name</a>, <a href="#configure_make-additional_inputs">additional_inputs</a>, <a href="#configure_make-additional_tools">additional_tools</a>, <a href="#configure_make-alwayslink">alwayslink</a>, <a href="#configure_make-autoconf">autoconf</a>, <a href="#configure_make-autoconf_env_vars">autoconf_env_vars</a>,
|
||||
<a href="#configure_make-autoconf_options">autoconf_options</a>, <a href="#configure_make-autogen">autogen</a>, <a href="#configure_make-autogen_command">autogen_command</a>, <a href="#configure_make-autogen_env_vars">autogen_env_vars</a>, <a href="#configure_make-autogen_options">autogen_options</a>,
|
||||
<a href="#configure_make-autoreconf">autoreconf</a>, <a href="#configure_make-autoreconf_env_vars">autoreconf_env_vars</a>, <a href="#configure_make-autoreconf_options">autoreconf_options</a>, <a href="#configure_make-binaries">binaries</a>, <a href="#configure_make-configure_command">configure_command</a>,
|
||||
<a href="#configure_make-configure_env_vars">configure_env_vars</a>, <a href="#configure_make-configure_in_place">configure_in_place</a>, <a href="#configure_make-configure_options">configure_options</a>, <a href="#configure_make-data">data</a>, <a href="#configure_make-defines">defines</a>, <a href="#configure_make-deps">deps</a>, <a href="#configure_make-env">env</a>,
|
||||
<a href="#configure_make-headers_only">headers_only</a>, <a href="#configure_make-install_prefix">install_prefix</a>, <a href="#configure_make-interface_libraries">interface_libraries</a>, <a href="#configure_make-lib_name">lib_name</a>, <a href="#configure_make-lib_source">lib_source</a>, <a href="#configure_make-linkopts">linkopts</a>,
|
||||
<a href="#configure_make-make_commands">make_commands</a>, <a href="#configure_make-out_bin_dir">out_bin_dir</a>, <a href="#configure_make-out_binaries">out_binaries</a>, <a href="#configure_make-out_headers_only">out_headers_only</a>, <a href="#configure_make-out_include_dir">out_include_dir</a>,
|
||||
<a href="#configure_make-out_interface_libs">out_interface_libs</a>, <a href="#configure_make-out_lib_dir">out_lib_dir</a>, <a href="#configure_make-out_shared_libs">out_shared_libs</a>, <a href="#configure_make-out_static_libs">out_static_libs</a>, <a href="#configure_make-postfix_script">postfix_script</a>,
|
||||
<a href="#configure_make-shared_libraries">shared_libraries</a>, <a href="#configure_make-static_libraries">static_libraries</a>, <a href="#configure_make-tools_deps">tools_deps</a>)
|
||||
configure_make(<a href="#configure_make-name">name</a>, <a href="#configure_make-additional_inputs">additional_inputs</a>, <a href="#configure_make-additional_tools">additional_tools</a>, <a href="#configure_make-alwayslink">alwayslink</a>, <a href="#configure_make-args">args</a>, <a href="#configure_make-autoconf">autoconf</a>,
|
||||
<a href="#configure_make-autoconf_env_vars">autoconf_env_vars</a>, <a href="#configure_make-autoconf_options">autoconf_options</a>, <a href="#configure_make-autogen">autogen</a>, <a href="#configure_make-autogen_command">autogen_command</a>, <a href="#configure_make-autogen_env_vars">autogen_env_vars</a>,
|
||||
<a href="#configure_make-autogen_options">autogen_options</a>, <a href="#configure_make-autoreconf">autoreconf</a>, <a href="#configure_make-autoreconf_env_vars">autoreconf_env_vars</a>, <a href="#configure_make-autoreconf_options">autoreconf_options</a>, <a href="#configure_make-binaries">binaries</a>,
|
||||
<a href="#configure_make-configure_command">configure_command</a>, <a href="#configure_make-configure_env_vars">configure_env_vars</a>, <a href="#configure_make-configure_in_place">configure_in_place</a>, <a href="#configure_make-configure_options">configure_options</a>, <a href="#configure_make-data">data</a>,
|
||||
<a href="#configure_make-defines">defines</a>, <a href="#configure_make-deps">deps</a>, <a href="#configure_make-env">env</a>, <a href="#configure_make-headers_only">headers_only</a>, <a href="#configure_make-install_prefix">install_prefix</a>, <a href="#configure_make-interface_libraries">interface_libraries</a>, <a href="#configure_make-lib_name">lib_name</a>,
|
||||
<a href="#configure_make-lib_source">lib_source</a>, <a href="#configure_make-linkopts">linkopts</a>, <a href="#configure_make-make_commands">make_commands</a>, <a href="#configure_make-out_bin_dir">out_bin_dir</a>, <a href="#configure_make-out_binaries">out_binaries</a>, <a href="#configure_make-out_headers_only">out_headers_only</a>,
|
||||
<a href="#configure_make-out_include_dir">out_include_dir</a>, <a href="#configure_make-out_interface_libs">out_interface_libs</a>, <a href="#configure_make-out_lib_dir">out_lib_dir</a>, <a href="#configure_make-out_shared_libs">out_shared_libs</a>, <a href="#configure_make-out_static_libs">out_static_libs</a>,
|
||||
<a href="#configure_make-postfix_script">postfix_script</a>, <a href="#configure_make-shared_libraries">shared_libraries</a>, <a href="#configure_make-static_libraries">static_libraries</a>, <a href="#configure_make-targets">targets</a>, <a href="#configure_make-tools_deps">tools_deps</a>)
|
||||
</pre>
|
||||
|
||||
Rule for building external libraries with configure-make pattern. Some 'configure' script is invoked with --prefix=install (by default), and other parameters for compilation and linking, taken from Bazel C/C++ toolchain and passed dependencies. After configuration, GNU Make is called.
|
||||
|
@ -164,6 +168,7 @@ Rule for building external libraries with configure-make pattern. Some 'configur
|
|||
| <a id="configure_make-additional_inputs"></a>additional_inputs | Optional additional inputs to be declared as needed for the shell script action.Not used by the shell script part in cc_external_rule_impl. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="configure_make-additional_tools"></a>additional_tools | Optional additional tools needed for the building. Not used by the shell script part in cc_external_rule_impl. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="configure_make-alwayslink"></a>alwayslink | Optional. if true, link all the object files from the static library, even if they are not used. | Boolean | optional | False |
|
||||
| <a id="configure_make-args"></a>args | A list of arguments to pass to the call to <code>make</code> | List of strings | optional | [] |
|
||||
| <a id="configure_make-autoconf"></a>autoconf | Set to True if 'autoconf' should be invoked before 'configure', currently requires 'configure_in_place' to be True. | Boolean | optional | False |
|
||||
| <a id="configure_make-autoconf_env_vars"></a>autoconf_env_vars | Environment variables to be set for 'autoconf' invocation. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="configure_make-autoconf_options"></a>autoconf_options | Any options to be put in the 'autoconf.sh' command line. | List of strings | optional | [] |
|
||||
|
@ -201,6 +206,7 @@ Rule for building external libraries with configure-make pattern. Some 'configur
|
|||
| <a id="configure_make-postfix_script"></a>postfix_script | Optional part of the shell script to be added after the make commands | String | optional | "" |
|
||||
| <a id="configure_make-shared_libraries"></a>shared_libraries | __deprecated__: Use <code>out_shared_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="configure_make-static_libraries"></a>static_libraries | __deprecated__: Use <code>out_static_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="configure_make-targets"></a>targets | A list of targets within the foreign build system to produce. An empty string (<code>""</code>) will result in a call to the underlying build system with no explicit target set | List of strings | optional | ["", "install"] |
|
||||
| <a id="configure_make-tools_deps"></a>tools_deps | Optional tools to be copied into the directory structure. Similar to deps, those directly required for the external building of the library/binaries. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
|
||||
|
||||
|
@ -209,11 +215,11 @@ Rule for building external libraries with configure-make pattern. Some 'configur
|
|||
## make
|
||||
|
||||
<pre>
|
||||
make(<a href="#make-name">name</a>, <a href="#make-additional_inputs">additional_inputs</a>, <a href="#make-additional_tools">additional_tools</a>, <a href="#make-alwayslink">alwayslink</a>, <a href="#make-binaries">binaries</a>, <a href="#make-data">data</a>, <a href="#make-defines">defines</a>, <a href="#make-deps">deps</a>, <a href="#make-env">env</a>,
|
||||
<a href="#make-headers_only">headers_only</a>, <a href="#make-interface_libraries">interface_libraries</a>, <a href="#make-keep_going">keep_going</a>, <a href="#make-lib_name">lib_name</a>, <a href="#make-lib_source">lib_source</a>, <a href="#make-linkopts">linkopts</a>, <a href="#make-make_commands">make_commands</a>,
|
||||
<a href="#make-make_env_vars">make_env_vars</a>, <a href="#make-out_bin_dir">out_bin_dir</a>, <a href="#make-out_binaries">out_binaries</a>, <a href="#make-out_headers_only">out_headers_only</a>, <a href="#make-out_include_dir">out_include_dir</a>, <a href="#make-out_interface_libs">out_interface_libs</a>,
|
||||
<a href="#make-out_lib_dir">out_lib_dir</a>, <a href="#make-out_shared_libs">out_shared_libs</a>, <a href="#make-out_static_libs">out_static_libs</a>, <a href="#make-postfix_script">postfix_script</a>, <a href="#make-prefix">prefix</a>, <a href="#make-shared_libraries">shared_libraries</a>,
|
||||
<a href="#make-static_libraries">static_libraries</a>, <a href="#make-tools_deps">tools_deps</a>)
|
||||
make(<a href="#make-name">name</a>, <a href="#make-additional_inputs">additional_inputs</a>, <a href="#make-additional_tools">additional_tools</a>, <a href="#make-alwayslink">alwayslink</a>, <a href="#make-args">args</a>, <a href="#make-binaries">binaries</a>, <a href="#make-data">data</a>, <a href="#make-defines">defines</a>, <a href="#make-deps">deps</a>,
|
||||
<a href="#make-env">env</a>, <a href="#make-headers_only">headers_only</a>, <a href="#make-interface_libraries">interface_libraries</a>, <a href="#make-keep_going">keep_going</a>, <a href="#make-lib_name">lib_name</a>, <a href="#make-lib_source">lib_source</a>, <a href="#make-linkopts">linkopts</a>,
|
||||
<a href="#make-make_commands">make_commands</a>, <a href="#make-make_env_vars">make_env_vars</a>, <a href="#make-out_bin_dir">out_bin_dir</a>, <a href="#make-out_binaries">out_binaries</a>, <a href="#make-out_headers_only">out_headers_only</a>, <a href="#make-out_include_dir">out_include_dir</a>,
|
||||
<a href="#make-out_interface_libs">out_interface_libs</a>, <a href="#make-out_lib_dir">out_lib_dir</a>, <a href="#make-out_shared_libs">out_shared_libs</a>, <a href="#make-out_static_libs">out_static_libs</a>, <a href="#make-postfix_script">postfix_script</a>, <a href="#make-prefix">prefix</a>,
|
||||
<a href="#make-shared_libraries">shared_libraries</a>, <a href="#make-static_libraries">static_libraries</a>, <a href="#make-targets">targets</a>, <a href="#make-tools_deps">tools_deps</a>)
|
||||
</pre>
|
||||
|
||||
Rule for building external libraries with GNU Make. GNU Make commands (make and make install by default) are invoked with prefix="install" (by default), and other environment variables for compilation and linking, taken from Bazel C/C++ toolchain and passed dependencies.
|
||||
|
@ -227,6 +233,7 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and
|
|||
| <a id="make-additional_inputs"></a>additional_inputs | Optional additional inputs to be declared as needed for the shell script action.Not used by the shell script part in cc_external_rule_impl. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="make-additional_tools"></a>additional_tools | Optional additional tools needed for the building. Not used by the shell script part in cc_external_rule_impl. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="make-alwayslink"></a>alwayslink | Optional. if true, link all the object files from the static library, even if they are not used. | Boolean | optional | False |
|
||||
| <a id="make-args"></a>args | A list of arguments to pass to the call to <code>make</code> | List of strings | optional | [] |
|
||||
| <a id="make-binaries"></a>binaries | __deprecated__: Use <code>out_binaries</code> instead. | List of strings | optional | [] |
|
||||
| <a id="make-data"></a>data | Files needed by this rule at runtime. May list file or rule targets. Generally allows any target. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
| <a id="make-defines"></a>defines | Optional compilation definitions to be passed to the dependencies of this library. They are NOT passed to the compiler, you should duplicate them in the configuration options. | List of strings | optional | [] |
|
||||
|
@ -234,12 +241,12 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and
|
|||
| <a id="make-env"></a>env | Environment variables to set during the build. $(execpath) macros may be used to point at files which are listed as data deps, tools_deps, or additional_tools, but unlike with other rules, these will be replaced with absolute paths to those files, because the build does not run in the exec root. No other macros are supported. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="make-headers_only"></a>headers_only | __deprecated__: Use <code>out_headers_only</code> instead. | Boolean | optional | False |
|
||||
| <a id="make-interface_libraries"></a>interface_libraries | __deprecated__: Use <code>out_interface_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="make-keep_going"></a>keep_going | Keep going when some targets can not be made, -k flag is passed to make (applies only if make_commands attribute is not set). Please have a look at _create_make_script for default make_commands. | Boolean | optional | True |
|
||||
| <a id="make-keep_going"></a>keep_going | __deprecated__: To maintain this behavior, pass <code>-k</code> to the <code>args</code> attribute when not using the <code>make_commands</code> attribute. | Boolean | optional | True |
|
||||
| <a id="make-lib_name"></a>lib_name | Library name. Defines the name of the install directory and the name of the static library, if no output files parameters are defined (any of static_libraries, shared_libraries, interface_libraries, binaries_names) Optional. If not defined, defaults to the target's name. | String | optional | "" |
|
||||
| <a id="make-lib_source"></a>lib_source | Label with source code to build. Typically a filegroup for the source of remote repository. Mandatory. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
| <a id="make-linkopts"></a>linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] |
|
||||
| <a id="make-make_commands"></a>make_commands | Overriding make_commands default value to be empty, then we can provide better default value programmatically | List of strings | optional | [] |
|
||||
| <a id="make-make_env_vars"></a>make_env_vars | Environment variables to be set for the 'configure' invocation. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="make-make_commands"></a>make_commands | __deprecated__: A list of hard coded bash commands for building source code. It's recommended to leave this empty and use the <code>targets</code> + <code>args</code> attributes. | List of strings | optional | [] |
|
||||
| <a id="make-make_env_vars"></a>make_env_vars | __deprecated__: Use the <code>env</code> attribute | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
|
||||
| <a id="make-out_bin_dir"></a>out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" |
|
||||
| <a id="make-out_binaries"></a>out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] |
|
||||
| <a id="make-out_headers_only"></a>out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False |
|
||||
|
@ -249,9 +256,10 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and
|
|||
| <a id="make-out_shared_libs"></a>out_shared_libs | Optional names of the resulting shared libraries. | List of strings | optional | [] |
|
||||
| <a id="make-out_static_libs"></a>out_static_libs | Optional names of the resulting static libraries. Note that if <code>out_headers_only</code>, <code>out_static_libs</code>, <code>out_shared_libs</code>, and <code>out_binaries</code> are not set, default <code>lib_name.a</code>/<code>lib_name.lib</code> static library is assumed | List of strings | optional | [] |
|
||||
| <a id="make-postfix_script"></a>postfix_script | Optional part of the shell script to be added after the make commands | String | optional | "" |
|
||||
| <a id="make-prefix"></a>prefix | Install prefix, an absolute path. Passed to the GNU make via "make install PREFIX=<value>". By default, the install directory created under sandboxed execution root is used. Build results are copied to the Bazel's output directory, so the prefix is only important if it is recorded into any text files by Makefile script. In that case, it is important to note that rules_foreign_cc is overriding the paths under execution root with "BAZEL_GEN_ROOT" value. | String | optional | "" |
|
||||
| <a id="make-prefix"></a>prefix | __deprecated__: To maintain this behavior, pass <code>PREFIX=<value></code> to the <code>args</code> attribute | String | optional | "" |
|
||||
| <a id="make-shared_libraries"></a>shared_libraries | __deprecated__: Use <code>out_shared_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="make-static_libraries"></a>static_libraries | __deprecated__: Use <code>out_static_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="make-targets"></a>targets | A list of targets within the foreign build system to produce. An empty string (<code>""</code>) will result in a call to the underlying build system with no explicit target set | List of strings | optional | ["", "install"] |
|
||||
| <a id="make-tools_deps"></a>tools_deps | Optional tools to be copied into the directory structure. Similar to deps, those directly required for the external building of the library/binaries. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
|
||||
|
||||
|
@ -260,7 +268,7 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and
|
|||
## make_tool
|
||||
|
||||
<pre>
|
||||
make_tool(<a href="#make_tool-name">name</a>, <a href="#make_tool-make_srcs">make_srcs</a>)
|
||||
make_tool(<a href="#make_tool-name">name</a>, <a href="#make_tool-srcs">srcs</a>)
|
||||
</pre>
|
||||
|
||||
Rule for building Make. Invokes configure script and make install.
|
||||
|
@ -271,7 +279,7 @@ Rule for building Make. Invokes configure script and make install.
|
|||
| Name | Description | Type | Mandatory | Default |
|
||||
| :------------- | :------------- | :------------- | :------------- | :------------- |
|
||||
| <a id="make_tool-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|
||||
| <a id="make_tool-make_srcs"></a>make_srcs | target with the Make sources | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
| <a id="make_tool-srcs"></a>srcs | The target containing the build tool's sources | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
|
||||
|
||||
<a id="#native_tool_toolchain"></a>
|
||||
|
@ -340,7 +348,7 @@ Rule for building external libraries with [Ninja](https://ninja-build.org/).
|
|||
| <a id="ninja-postfix_script"></a>postfix_script | Optional part of the shell script to be added after the make commands | String | optional | "" |
|
||||
| <a id="ninja-shared_libraries"></a>shared_libraries | __deprecated__: Use <code>out_shared_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="ninja-static_libraries"></a>static_libraries | __deprecated__: Use <code>out_static_libs</code> instead. | List of strings | optional | [] |
|
||||
| <a id="ninja-targets"></a>targets | A list of ninja targets to build. To call the default target, simply pass <code>""</code> as one of the items to this attribute. | List of strings | optional | [] |
|
||||
| <a id="ninja-targets"></a>targets | A list of targets with in the foreign build system to produce. An empty string (<code>""</code>) will result in a call to the underlying build system with no explicit target set | List of strings | optional | [] |
|
||||
| <a id="ninja-tools_deps"></a>tools_deps | Optional tools to be copied into the directory structure. Similar to deps, those directly required for the external building of the library/binaries. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
|
||||
|
||||
|
||||
|
@ -349,10 +357,10 @@ Rule for building external libraries with [Ninja](https://ninja-build.org/).
|
|||
## ninja_tool
|
||||
|
||||
<pre>
|
||||
ninja_tool(<a href="#ninja_tool-name">name</a>, <a href="#ninja_tool-ninja_srcs">ninja_srcs</a>)
|
||||
ninja_tool(<a href="#ninja_tool-name">name</a>, <a href="#ninja_tool-srcs">srcs</a>)
|
||||
</pre>
|
||||
|
||||
Rule for building Ninja. Invokes configure script and make install.
|
||||
Rule for building Ninja. Invokes configure script.
|
||||
|
||||
**ATTRIBUTES**
|
||||
|
||||
|
@ -360,7 +368,7 @@ Rule for building Ninja. Invokes configure script and make install.
|
|||
| Name | Description | Type | Mandatory | Default |
|
||||
| :------------- | :------------- | :------------- | :------------- | :------------- |
|
||||
| <a id="ninja_tool-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
|
||||
| <a id="ninja_tool-ninja_srcs"></a>ninja_srcs | - | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
| <a id="ninja_tool-srcs"></a>srcs | The target containing the build tool's sources | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
|
||||
|
||||
|
||||
<a id="#ForeignCcArtifact"></a>
|
||||
|
|
|
@ -23,10 +23,9 @@ cmake(
|
|||
|
||||
cmake(
|
||||
name = "libhello_win",
|
||||
cmake_options = ["-G \"Visual Studio 15 2017\" -A x64"],
|
||||
generate_args = ["-G \"Visual Studio 15 2017\" -A x64"],
|
||||
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",
|
||||
out_static_libs = ["hello.lib"],
|
||||
|
@ -34,12 +33,8 @@ cmake(
|
|||
|
||||
cmake(
|
||||
name = "libhello_win_ninja",
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
lib_source = ":srcs",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
# pass include/version123 to C/C++ provider as include directory
|
||||
out_include_dir = "include/version123",
|
||||
out_static_libs = ["hello.lib"],
|
||||
|
@ -47,12 +42,8 @@ cmake(
|
|||
|
||||
cmake(
|
||||
name = "libhello_win_nmake",
|
||||
cmake_options = ["-G \"NMake Makefiles\""],
|
||||
generate_args = ["-G \"NMake Makefiles\""],
|
||||
lib_source = ":srcs",
|
||||
make_commands = [
|
||||
"nmake",
|
||||
"nmake install",
|
||||
],
|
||||
# pass include/version123 to C/C++ provider as include directory
|
||||
out_include_dir = "include/version123",
|
||||
out_static_libs = ["hello.lib"],
|
||||
|
|
|
@ -20,10 +20,12 @@ cmake(
|
|||
|
||||
cmake(
|
||||
name = "libhello_win",
|
||||
cmake_options = ["-G \"Visual Studio 15 2017\" -A x64"],
|
||||
generate_args = [
|
||||
"-G \"Visual Studio 15 2017\"",
|
||||
"-A x64",
|
||||
],
|
||||
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",
|
||||
out_static_libs = ["hello.lib"],
|
||||
|
@ -33,12 +35,8 @@ cmake(
|
|||
|
||||
cmake(
|
||||
name = "libhello_win_ninja",
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
lib_source = ":srcs",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
# pass include/version123 to C/C++ provider as include directory
|
||||
out_include_dir = "include/version123",
|
||||
out_static_libs = ["hello.lib"],
|
||||
|
@ -48,12 +46,8 @@ cmake(
|
|||
|
||||
cmake(
|
||||
name = "libhello_win_nmake",
|
||||
cmake_options = ["-G \"NMake Makefiles\""],
|
||||
generate_args = ["-G \"NMake Makefiles\""],
|
||||
lib_source = ":srcs",
|
||||
make_commands = [
|
||||
"nmake",
|
||||
"nmake install",
|
||||
],
|
||||
# pass include/version123 to C/C++ provider as include directory
|
||||
out_include_dir = "include/version123",
|
||||
out_static_libs = ["hello.lib"],
|
||||
|
|
|
@ -2,12 +2,8 @@ load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
|
|||
|
||||
cmake(
|
||||
name = "hello_world",
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
lib_source = "@cmake_hello_world_variant_src//:all",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
out_binaries = select({
|
||||
"//:macos": ["CMakeHelloWorld"],
|
||||
"//:windows": ["CMakeHelloWorld.exe"],
|
||||
|
|
|
@ -4,25 +4,17 @@ load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
|
|||
|
||||
cmake(
|
||||
name = "liba",
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
# Demonstrate non-alphanumeric name
|
||||
lib_name = "liba++",
|
||||
lib_source = "//cmake_synthetic/liba:a_srcs",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
postfix_script = "cp $$INSTALLDIR$$/lib/liba.a $$INSTALLDIR$$/lib/liba++.a",
|
||||
)
|
||||
|
||||
cmake(
|
||||
name = "libb",
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
lib_source = "//cmake_synthetic/libb:b_srcs",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
deps = [":liba"],
|
||||
)
|
||||
|
||||
|
@ -32,13 +24,9 @@ cmake(
|
|||
"LIBA_DIR": "$$EXT_BUILD_DEPS$$",
|
||||
"LIBB_DIR": "$$EXT_BUILD_DEPS$$",
|
||||
},
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
lib_name = "libc",
|
||||
lib_source = "//cmake_synthetic/libc:c_srcs",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
deps = [
|
||||
"//cmake_synthetic/liba:lib_a_bazel",
|
||||
"//cmake_synthetic/libb:lib_b_bazel",
|
||||
|
|
|
@ -12,12 +12,8 @@ cmake(
|
|||
# and the headers into $EXT_BUILD_DEPS/include
|
||||
"LIBA_DIR": "$EXT_BUILD_DEPS",
|
||||
},
|
||||
cmake_options = ["-GNinja"],
|
||||
generate_args = ["-GNinja"],
|
||||
lib_source = "//cmake_with_bazel_transitive/libb:b_srcs",
|
||||
make_commands = [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
out_static_libs = ["libb.a"],
|
||||
# This library is with public visibility, we can reuse it here.
|
||||
deps = ["//cmake_synthetic/liba:lib_a_bazel"],
|
||||
|
|
|
@ -11,22 +11,18 @@ cmake(
|
|||
},
|
||||
"//conditions:default": {},
|
||||
}),
|
||||
cmake_options = select({
|
||||
"@bazel_tools//src/conditions:windows": ["-G \"Visual Studio 15 2017\" -A x64"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
data = [
|
||||
"cmake_with_data.txt",
|
||||
"//cmake_with_data/lib_b",
|
||||
],
|
||||
lib_source = "//cmake_with_data/lib_a:srcs",
|
||||
make_commands = select({
|
||||
"@bazel_tools//src/conditions:windows": ["MSBuild.exe INSTALL.vcxproj"],
|
||||
"//conditions:default": [
|
||||
"make",
|
||||
"make install",
|
||||
generate_args = select({
|
||||
"@bazel_tools//src/conditions:windows": [
|
||||
"-G \"Visual Studio 15 2017\"",
|
||||
"-A x64",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
lib_source = "//cmake_with_data/lib_a:srcs",
|
||||
out_static_libs = select({
|
||||
"@bazel_tools//src/conditions:windows": ["lib_a.lib"],
|
||||
"//conditions:default": ["lib_a.a"],
|
||||
|
|
|
@ -12,9 +12,9 @@ configure_make(
|
|||
name = "simple",
|
||||
configure_in_place = True,
|
||||
lib_source = "//configure_with_bazel_transitive/simple_lib:simple_srcs",
|
||||
make_commands = [
|
||||
"make simple",
|
||||
"make install",
|
||||
targets = [
|
||||
"simple",
|
||||
"install",
|
||||
],
|
||||
deps = [":built_with_bazel"],
|
||||
)
|
||||
|
|
|
@ -5,6 +5,7 @@ make(
|
|||
name = "make_lib",
|
||||
env = {
|
||||
"CLANG_WRAPPER": "$(execpath //make_simple/code:clang_wrapper.sh)",
|
||||
"PREFIX": "$$INSTALLDIR$$",
|
||||
},
|
||||
lib_source = "//make_simple/code:srcs",
|
||||
out_static_libs = ["liba.a"],
|
||||
|
|
|
@ -15,12 +15,6 @@ cmake(
|
|||
},
|
||||
cmake_options = ["-GNinja"],
|
||||
lib_source = ":all_srcs",
|
||||
make_commands = [
|
||||
# The correct path to the ninja tool is detected from the selected ninja_toolchain.
|
||||
# and "ninja" will be replaced with that path if needed
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
out_static_libs = select({
|
||||
"@platforms//os:windows": ["cares.lib"],
|
||||
"//conditions:default": ["libcares.a"],
|
||||
|
|
|
@ -35,16 +35,6 @@ cmake(
|
|||
}),
|
||||
generate_crosstool_file = False,
|
||||
lib_source = ":all_srcs",
|
||||
make_commands = select({
|
||||
"@platforms//os:windows": [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"make",
|
||||
"make install",
|
||||
],
|
||||
}),
|
||||
out_static_libs = select({
|
||||
"@platforms//os:windows": ["libcurl.lib"],
|
||||
"//conditions:default": ["libcurl.a"],
|
||||
|
|
|
@ -20,9 +20,9 @@ configure_make(
|
|||
"--enable-static=yes",
|
||||
],
|
||||
lib_source = "@iconv//:all",
|
||||
make_commands = ["make install-lib"],
|
||||
out_static_libs = [
|
||||
"libiconv.a",
|
||||
],
|
||||
targets = ["install-lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
|
|
@ -37,14 +37,14 @@ configure_make(
|
|||
] + CONFIGURE_OPTIONS,
|
||||
}),
|
||||
lib_source = ":all_srcs",
|
||||
make_commands = [
|
||||
"make build_libs",
|
||||
"make install_dev",
|
||||
],
|
||||
out_static_libs = [
|
||||
"libcrypto.a",
|
||||
"libssl.a",
|
||||
],
|
||||
targets = [
|
||||
"build_libs",
|
||||
"install_dev",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
|
|
|
@ -14,16 +14,6 @@ cmake(
|
|||
"//conditions:default": [],
|
||||
}),
|
||||
lib_source = ":all_srcs",
|
||||
make_commands = select({
|
||||
"@platforms//os:windows": [
|
||||
"ninja",
|
||||
"ninja install",
|
||||
],
|
||||
"//conditions:default": [
|
||||
"make",
|
||||
"make install",
|
||||
],
|
||||
}),
|
||||
out_static_libs = select({
|
||||
"@platforms//os:windows": ["zlibstatic.lib"],
|
||||
"//conditions:default": ["libz.a"],
|
||||
|
|
|
@ -9,10 +9,10 @@ load(
|
|||
"create_attrs",
|
||||
)
|
||||
|
||||
def _boost_build(ctx):
|
||||
def _boost_build_impl(ctx):
|
||||
attrs = create_attrs(
|
||||
ctx.attr,
|
||||
configure_name = "BuildBoost",
|
||||
configure_name = "BoostBuild",
|
||||
create_configure_script = _create_configure_script,
|
||||
make_commands = ["./b2 install {} --prefix=.".format(" ".join(ctx.attr.user_options))],
|
||||
)
|
||||
|
@ -30,6 +30,8 @@ def _create_configure_script(configureParameters):
|
|||
|
||||
def _attrs():
|
||||
attrs = dict(CC_EXTERNAL_RULE_ATTRIBUTES)
|
||||
attrs.pop("targets")
|
||||
attrs.pop("make_commands")
|
||||
attrs.update({
|
||||
"bootstrap_options": attr.string_list(
|
||||
doc = "any additional flags to pass to bootstrap.sh",
|
||||
|
@ -47,7 +49,7 @@ boost_build = rule(
|
|||
attrs = _attrs(),
|
||||
fragments = CC_EXTERNAL_RULE_FRAGMENTS,
|
||||
output_to_genfiles = True,
|
||||
implementation = _boost_build,
|
||||
implementation = _boost_build_impl,
|
||||
toolchains = [
|
||||
"@rules_foreign_cc//foreign_cc/private/shell_toolchain/toolchains:shell_commands",
|
||||
"@bazel_tools//tools/cpp:toolchain_type",
|
||||
|
|
|
@ -8,10 +8,7 @@ load(
|
|||
"is_debug_mode",
|
||||
)
|
||||
load("//foreign_cc/private:cmake_script.bzl", "create_cmake_script")
|
||||
load(
|
||||
"//foreign_cc/private:detect_root.bzl",
|
||||
"detect_root",
|
||||
)
|
||||
load("//foreign_cc/private:detect_root.bzl", "detect_root")
|
||||
load(
|
||||
"//foreign_cc/private:framework.bzl",
|
||||
"CC_EXTERNAL_RULE_ATTRIBUTES",
|
||||
|
@ -19,6 +16,10 @@ load(
|
|||
"cc_external_rule_impl",
|
||||
"create_attrs",
|
||||
)
|
||||
load(
|
||||
"//foreign_cc/private:shell_script_helper.bzl",
|
||||
"os_name",
|
||||
)
|
||||
load(
|
||||
"//toolchains/native_tools:tool_access.bzl",
|
||||
"get_cmake_data",
|
||||
|
@ -28,39 +29,37 @@ load(
|
|||
|
||||
def _cmake_impl(ctx):
|
||||
cmake_data = get_cmake_data(ctx)
|
||||
make_data = get_make_data(ctx)
|
||||
|
||||
tools_deps = ctx.attr.tools_deps + cmake_data.deps + make_data.deps
|
||||
tools_deps = ctx.attr.tools_deps + cmake_data.deps
|
||||
env = dict(ctx.attr.env)
|
||||
|
||||
ninja_data = get_ninja_data(ctx)
|
||||
make_commands = ctx.attr.make_commands
|
||||
if _uses_ninja(ctx.attr.make_commands):
|
||||
tools_deps += ninja_data.deps
|
||||
make_commands = [command.replace("ninja", ninja_data.path) for command in make_commands]
|
||||
generator, generate_args = _get_generator_target(ctx)
|
||||
if "Unix Makefiles" == generator:
|
||||
make_data = get_make_data(ctx)
|
||||
tools_deps.extend(make_data.deps)
|
||||
env.update({"CMAKE_MAKE_PROGRAM": make_data.path})
|
||||
elif "Ninja" in generator:
|
||||
ninja_data = get_ninja_data(ctx)
|
||||
tools_deps.extend(ninja_data.deps)
|
||||
env.update({"CMAKE_MAKE_PROGRAM": ninja_data.path})
|
||||
|
||||
attrs = create_attrs(
|
||||
ctx.attr,
|
||||
env = env,
|
||||
generator = generator,
|
||||
generate_args = generate_args,
|
||||
configure_name = "CMake",
|
||||
create_configure_script = _create_configure_script,
|
||||
postfix_script = "##copy_dir_contents_to_dir## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ $$INSTALLDIR$$\n" + ctx.attr.postfix_script,
|
||||
tools_deps = tools_deps,
|
||||
cmake_path = cmake_data.path,
|
||||
ninja_path = ninja_data.path,
|
||||
make_path = make_data.path,
|
||||
make_commands = make_commands,
|
||||
)
|
||||
|
||||
return cc_external_rule_impl(ctx, attrs)
|
||||
|
||||
def _uses_ninja(make_commands):
|
||||
for command in make_commands:
|
||||
(before, separator, after) = command.partition(" ")
|
||||
if before == "ninja":
|
||||
return True
|
||||
return False
|
||||
|
||||
def _create_configure_script(configureParameters):
|
||||
ctx = configureParameters.ctx
|
||||
attrs = configureParameters.attrs
|
||||
inputs = configureParameters.inputs
|
||||
|
||||
root = detect_root(ctx.attr.lib_source)
|
||||
|
@ -73,23 +72,136 @@ def _create_configure_script(configureParameters):
|
|||
flags = get_flags_info(ctx, "<TARGET>")
|
||||
no_toolchain_file = ctx.attr.cache_entries.get("CMAKE_TOOLCHAIN_FILE") or not ctx.attr.generate_crosstool_file
|
||||
|
||||
cmake_commands = []
|
||||
|
||||
# If the legacy `make_commands` attribute was not set, use the new
|
||||
# `targets` api for building our target.
|
||||
if not ctx.attr.make_commands:
|
||||
data = ctx.attr.data + getattr(ctx.attr, "tools_deps", [])
|
||||
configuration = "Debug" if is_debug_mode(ctx) else "Release"
|
||||
|
||||
# Generate a list of arguments for cmake's build command
|
||||
build_args = " ".join([
|
||||
ctx.expand_location(arg, data)
|
||||
for arg in ctx.attr.build_args
|
||||
])
|
||||
|
||||
# Generate commands for all the targets, ensuring there's
|
||||
# always at least 1 call to the default target.
|
||||
for target in ctx.attr.targets or [""]:
|
||||
# Note that even though directory is always passed, the
|
||||
# following arguments can take precedence.
|
||||
cmake_commands.append("{cmake} --build {dir} --config {config} {args} {target}".format(
|
||||
cmake = attrs.cmake_path,
|
||||
dir = ".",
|
||||
args = build_args,
|
||||
target = target,
|
||||
config = configuration,
|
||||
))
|
||||
|
||||
if ctx.attr.install:
|
||||
# Generate a list of arguments for cmake's install command
|
||||
install_args = " ".join([
|
||||
ctx.expand_location(arg, data)
|
||||
for arg in ctx.attr.install_args
|
||||
])
|
||||
|
||||
cmake_commands.append("{cmake} --install {dir} --config {config} {args}".format(
|
||||
cmake = attrs.cmake_path,
|
||||
dir = ".",
|
||||
args = install_args,
|
||||
config = configuration,
|
||||
))
|
||||
|
||||
define_install_prefix = "export INSTALL_PREFIX=\"" + _get_install_prefix(ctx) + "\"\n"
|
||||
configure_script = create_cmake_script(
|
||||
workspace_name = ctx.workspace_name,
|
||||
cmake_path = configureParameters.attrs.cmake_path,
|
||||
generator = attrs.generator,
|
||||
cmake_path = attrs.cmake_path,
|
||||
tools = tools,
|
||||
flags = flags,
|
||||
install_prefix = "$$INSTALL_PREFIX$$",
|
||||
root = root,
|
||||
no_toolchain_file = no_toolchain_file,
|
||||
user_cache = dict(ctx.attr.cache_entries),
|
||||
user_env = dict(ctx.attr.env_vars),
|
||||
options = ctx.attr.cmake_options,
|
||||
user_env = getattr(ctx.attr, "env_vars", {}),
|
||||
options = attrs.generate_args,
|
||||
cmake_commands = cmake_commands,
|
||||
include_dirs = inputs.include_dirs,
|
||||
is_debug_mode = is_debug_mode(ctx),
|
||||
)
|
||||
return define_install_prefix + configure_script
|
||||
|
||||
def _get_generator_target(ctx):
|
||||
"""Parse the genrator arguments for a generator declaration
|
||||
|
||||
If none is found, a default will be chosen
|
||||
|
||||
Args:
|
||||
ctx (ctx): The rule's context object
|
||||
|
||||
Returns:
|
||||
tuple: (str, list) the generator and a list of arguments with the generator arg removed
|
||||
"""
|
||||
known_generators = [
|
||||
"Borland Makefiles",
|
||||
"Green Hills MULTI",
|
||||
"MinGW Makefiles",
|
||||
"MSYS Makefiles",
|
||||
"Ninja",
|
||||
"Ninja Multi-Config",
|
||||
"NMake Makefiles JOM",
|
||||
"NMake Makefiles",
|
||||
"Unix Makefiles",
|
||||
"Visual Studio 10 2010",
|
||||
"Visual Studio 11 2012",
|
||||
"Visual Studio 12 2013",
|
||||
"Visual Studio 14 2015",
|
||||
"Visual Studio 15 2017",
|
||||
"Visual Studio 16 2019",
|
||||
"Visual Studio 9 2008",
|
||||
"Watcom WMake",
|
||||
"Xcode",
|
||||
]
|
||||
|
||||
generator = None
|
||||
|
||||
generator_definitions = []
|
||||
generate_args = ctx.attr.generate_args + getattr(ctx.attr, "cmake_options", [])
|
||||
for arg in generate_args:
|
||||
if arg.startswith("-G"):
|
||||
generator_definitions.append(arg)
|
||||
break
|
||||
|
||||
if len(generator_definitions) > 1:
|
||||
fail("Please specify no more than 1 generator argument. Arguments found: {}".format(generator_definitions))
|
||||
|
||||
for definition in generator_definitions:
|
||||
generator = definition[2:]
|
||||
generator = generator.strip(" =\"'")
|
||||
|
||||
# Remove the argument so it's not passed twice to the cmake command
|
||||
# See create_cmake_script for more details
|
||||
generate_args.remove(definition)
|
||||
|
||||
if not generator:
|
||||
execution_os_name = os_name(ctx)
|
||||
if "win" in execution_os_name:
|
||||
generator = "Ninja"
|
||||
elif "macos" in execution_os_name:
|
||||
generator = "Unix Makefiles"
|
||||
elif "linux" in execution_os_name:
|
||||
generator = "Unix Makefiles"
|
||||
else:
|
||||
fail("No generator set and no default is known. Please set the cmake `generator` attribute")
|
||||
|
||||
# Sanity check
|
||||
for gen in known_generators:
|
||||
if generator.startswith(gen):
|
||||
return generator, generate_args
|
||||
|
||||
fail("`{}` is not a known generator".format(generator))
|
||||
|
||||
def _get_install_prefix(ctx):
|
||||
if ctx.attr.install_prefix:
|
||||
return ctx.attr.install_prefix
|
||||
|
@ -100,9 +212,13 @@ def _get_install_prefix(ctx):
|
|||
def _attrs():
|
||||
attrs = dict(CC_EXTERNAL_RULE_ATTRIBUTES)
|
||||
attrs.update({
|
||||
"build_args": attr.string_list(
|
||||
doc = "Arguments for the CMake build command",
|
||||
mandatory = False,
|
||||
),
|
||||
"cache_entries": attr.string_dict(
|
||||
doc = (
|
||||
"CMake cache entries to initialize (they will be passed with -Dkey=value) " +
|
||||
"CMake cache entries to initialize (they will be passed with `-Dkey=value`) " +
|
||||
"Values, defined by the toolchain, will be joined with the values, passed here. " +
|
||||
"(Toolchain values come first)"
|
||||
),
|
||||
|
@ -110,32 +226,54 @@ def _attrs():
|
|||
default = {},
|
||||
),
|
||||
"cmake_options": attr.string_list(
|
||||
doc = "Other CMake options",
|
||||
doc = "__deprecated__: Use `generate_args`",
|
||||
mandatory = False,
|
||||
default = [],
|
||||
),
|
||||
"env_vars": attr.string_dict(
|
||||
doc = (
|
||||
"CMake environment variable values to join with toolchain-defined. " +
|
||||
"For example, additional CXXFLAGS."
|
||||
"For example, additional `CXXFLAGS`."
|
||||
),
|
||||
mandatory = False,
|
||||
default = {},
|
||||
),
|
||||
"generate_args": attr.string_list(
|
||||
doc = (
|
||||
"Arguments for CMake's generate command. Arguments should be passed as key/value pairs. eg: " +
|
||||
"`[\"-G Ninja\", \"--debug-output\", \"-DFOO=bar\"]`."
|
||||
),
|
||||
mandatory = False,
|
||||
default = [],
|
||||
),
|
||||
"generate_crosstool_file": attr.bool(
|
||||
doc = (
|
||||
"When True, CMake crosstool file will be generated from the toolchain values, " +
|
||||
"provided cache-entries and env_vars (some values will still be passed as -Dkey=value " +
|
||||
"and environment variables). " +
|
||||
"If CMAKE_TOOLCHAIN_FILE cache entry is passed, specified crosstool file will be used " +
|
||||
"When using this option to cross-compile, it is required to specify CMAKE_SYSTEM_NAME in the " +
|
||||
"cache_entries"
|
||||
"provided cache-entries and env_vars (some values will still be passed as `-Dkey=value` " +
|
||||
"and environment variables). If `CMAKE_TOOLCHAIN_FILE` cache entry is passed, " +
|
||||
"specified crosstool file will be used When using this option to cross-compile, " +
|
||||
"it is required to specify `CMAKE_SYSTEM_NAME` in the cache_entries"
|
||||
),
|
||||
mandatory = False,
|
||||
default = True,
|
||||
),
|
||||
"install": attr.bool(
|
||||
doc = "If True, the `cmake --install` comand will be performed after a build",
|
||||
default = True,
|
||||
),
|
||||
"install_args": attr.string_list(
|
||||
doc = "Arguments for the CMake install command",
|
||||
mandatory = False,
|
||||
),
|
||||
"install_prefix": attr.string(
|
||||
doc = "Relative install prefix to be passed to CMake in -DCMAKE_INSTALL_PREFIX",
|
||||
doc = "Relative install prefix to be passed to CMake in `-DCMAKE_INSTALL_PREFIX`",
|
||||
mandatory = False,
|
||||
),
|
||||
"make_commands": attr.string_list(
|
||||
doc = (
|
||||
"__deprecated__: Optional hard coded commands to replace the `cmake --build` commands. It's " +
|
||||
"recommended to leave this empty and use the `targets` + `build_args` attributes."
|
||||
),
|
||||
mandatory = False,
|
||||
),
|
||||
"working_directory": attr.string(
|
||||
|
|
|
@ -36,6 +36,7 @@ def _configure_make(ctx):
|
|||
|
||||
def _create_configure_script(configureParameters):
|
||||
ctx = configureParameters.ctx
|
||||
attrs = configureParameters.attrs
|
||||
inputs = configureParameters.inputs
|
||||
|
||||
root = detect_root(ctx.attr.lib_source)
|
||||
|
@ -46,6 +47,25 @@ def _create_configure_script(configureParameters):
|
|||
|
||||
define_install_prefix = "export INSTALL_PREFIX=\"" + _get_install_prefix(ctx) + "\"\n"
|
||||
|
||||
data = ctx.attr.data or list()
|
||||
|
||||
# Generate a list of arguments for make
|
||||
args = " ".join([
|
||||
ctx.expand_location(arg, data)
|
||||
for arg in ctx.attr.args
|
||||
])
|
||||
|
||||
make_commands = []
|
||||
|
||||
if not ctx.attr.make_commands:
|
||||
for target in ctx.attr.targets:
|
||||
make_commands.append("{make} -C $$EXT_BUILD_ROOT$$/{root} {target} {args}".format(
|
||||
make = attrs.make_path,
|
||||
root = root,
|
||||
args = args,
|
||||
target = target,
|
||||
))
|
||||
|
||||
configure = create_configure_script(
|
||||
workspace_name = ctx.workspace_name,
|
||||
# as default, pass execution OS as target OS
|
||||
|
@ -70,6 +90,7 @@ def _create_configure_script(configureParameters):
|
|||
autogen_command = ctx.attr.autogen_command,
|
||||
autogen_options = ctx.attr.autogen_options,
|
||||
autogen_env_vars = ctx.attr.autogen_env_vars,
|
||||
make_commands = make_commands,
|
||||
)
|
||||
return "\n".join([define_install_prefix, configure])
|
||||
|
||||
|
@ -83,6 +104,9 @@ def _get_install_prefix(ctx):
|
|||
def _attrs():
|
||||
attrs = dict(CC_EXTERNAL_RULE_ATTRIBUTES)
|
||||
attrs.update({
|
||||
"args": attr.string_list(
|
||||
doc = "A list of arguments to pass to the call to `make`",
|
||||
),
|
||||
"autoconf": attr.bool(
|
||||
mandatory = False,
|
||||
default = False,
|
||||
|
@ -161,7 +185,16 @@ def _attrs():
|
|||
),
|
||||
mandatory = False,
|
||||
),
|
||||
"targets": attr.string_list(
|
||||
doc = (
|
||||
"A list of targets within the foreign build system to produce. An empty string (`\"\"`) will result in " +
|
||||
"a call to the underlying build system with no explicit target set"
|
||||
),
|
||||
mandatory = False,
|
||||
default = ["", "install"],
|
||||
),
|
||||
})
|
||||
|
||||
return attrs
|
||||
|
||||
configure_make = rule(
|
||||
|
|
|
@ -29,12 +29,12 @@ def _make(ctx):
|
|||
create_configure_script = _create_make_script,
|
||||
tools_deps = tools_deps,
|
||||
make_path = make_data.path,
|
||||
make_commands = [],
|
||||
)
|
||||
return cc_external_rule_impl(ctx, attrs)
|
||||
|
||||
def _create_make_script(configureParameters):
|
||||
ctx = configureParameters.ctx
|
||||
attrs = configureParameters.attrs
|
||||
inputs = configureParameters.inputs
|
||||
|
||||
root = detect_root(ctx.attr.lib_source)
|
||||
|
@ -43,18 +43,24 @@ def _create_make_script(configureParameters):
|
|||
tools = get_tools_info(ctx)
|
||||
flags = get_flags_info(ctx)
|
||||
|
||||
make_commands = ctx.attr.make_commands or [
|
||||
"{make} {keep_going} -C $$EXT_BUILD_ROOT$$/{root}".format(
|
||||
make = configureParameters.attrs.make_path,
|
||||
keep_going = "-k" if ctx.attr.keep_going else "",
|
||||
root = root,
|
||||
),
|
||||
"{make} -C $$EXT_BUILD_ROOT$$/{root} install PREFIX={prefix}".format(
|
||||
make = configureParameters.attrs.make_path,
|
||||
root = root,
|
||||
prefix = install_prefix,
|
||||
),
|
||||
]
|
||||
data = ctx.attr.data or list()
|
||||
|
||||
# Generate a list of arguments for make
|
||||
args = " ".join([
|
||||
ctx.expand_location(arg, data)
|
||||
for arg in ctx.attr.args
|
||||
])
|
||||
|
||||
make_commands = []
|
||||
|
||||
if not ctx.attr.make_commands:
|
||||
for target in ctx.attr.targets:
|
||||
make_commands.append("{make} -C $$EXT_BUILD_ROOT$$/{root} {target} {args}".format(
|
||||
make = attrs.make_path,
|
||||
root = root,
|
||||
args = args,
|
||||
target = target,
|
||||
))
|
||||
|
||||
return create_make_script(
|
||||
workspace_name = ctx.workspace_name,
|
||||
|
@ -64,8 +70,8 @@ def _create_make_script(configureParameters):
|
|||
user_vars = dict(ctx.attr.make_env_vars),
|
||||
deps = ctx.attr.deps,
|
||||
inputs = inputs,
|
||||
make_commands = make_commands,
|
||||
prefix = install_prefix,
|
||||
make_commands = make_commands,
|
||||
)
|
||||
|
||||
def _get_install_prefix(ctx):
|
||||
|
@ -76,38 +82,42 @@ def _get_install_prefix(ctx):
|
|||
def _attrs():
|
||||
attrs = dict(CC_EXTERNAL_RULE_ATTRIBUTES)
|
||||
attrs.update({
|
||||
"args": attr.string_list(
|
||||
doc = "A list of arguments to pass to the call to `make`",
|
||||
),
|
||||
"keep_going": attr.bool(
|
||||
doc = (
|
||||
"Keep going when some targets can not be made, -k flag is passed to make " +
|
||||
"(applies only if make_commands attribute is not set). " +
|
||||
"Please have a look at _create_make_script for default make_commands."
|
||||
"__deprecated__: To maintain this behavior, pass `-k` to the `args` attribute " +
|
||||
"when not using the `make_commands` attribute."
|
||||
),
|
||||
mandatory = False,
|
||||
default = True,
|
||||
),
|
||||
"make_commands": attr.string_list(
|
||||
doc = (
|
||||
"Overriding make_commands default value to be empty, " +
|
||||
"then we can provide better default value programmatically "
|
||||
"__deprecated__: A list of hard coded bash commands for building source code. It's " +
|
||||
"recommended to leave this empty and use the `targets` + `args` attributes."
|
||||
),
|
||||
mandatory = False,
|
||||
default = [],
|
||||
),
|
||||
"make_env_vars": attr.string_dict(
|
||||
doc = "Environment variables to be set for the 'configure' invocation.",
|
||||
doc = "__deprecated__: Use the `env` attribute",
|
||||
),
|
||||
"prefix": attr.string(
|
||||
doc = (
|
||||
"Install prefix, an absolute path. " +
|
||||
"Passed to the GNU make via \"make install PREFIX=<value>\". " +
|
||||
"By default, the install directory created under sandboxed execution root is used. " +
|
||||
"Build results are copied to the Bazel's output directory, so the prefix is only important " +
|
||||
"if it is recorded into any text files by Makefile script. " +
|
||||
"In that case, it is important to note that rules_foreign_cc is overriding the paths under " +
|
||||
"execution root with \"BAZEL_GEN_ROOT\" value."
|
||||
"__deprecated__: To maintain this behavior, pass `PREFIX=<value>` to the `args` attribute"
|
||||
),
|
||||
mandatory = False,
|
||||
),
|
||||
"targets": attr.string_list(
|
||||
doc = (
|
||||
"A list of targets within the foreign build system to produce. An empty string (`\"\"`) will result in " +
|
||||
"a call to the underlying build system with no explicit target set"
|
||||
),
|
||||
mandatory = False,
|
||||
default = ["", "install"],
|
||||
),
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
|
|
@ -100,12 +100,6 @@ def _attrs():
|
|||
"directory of the `lib_sources` attribute if this attribute is not set"
|
||||
),
|
||||
),
|
||||
"targets": attr.string_list(
|
||||
doc = (
|
||||
"A list of ninja targets to build. To call the default target, simply pass `\"\"` as " +
|
||||
"one of the items to this attribute."
|
||||
),
|
||||
),
|
||||
})
|
||||
return attrs
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ load(":cc_toolchain_util.bzl", "absolutize_path_in_str")
|
|||
|
||||
def create_cmake_script(
|
||||
workspace_name,
|
||||
generator,
|
||||
cmake_path,
|
||||
tools,
|
||||
flags,
|
||||
|
@ -13,12 +14,14 @@ def create_cmake_script(
|
|||
user_cache,
|
||||
user_env,
|
||||
options,
|
||||
cmake_commands,
|
||||
include_dirs = [],
|
||||
is_debug_mode = True):
|
||||
"""Constructs CMake script to be passed to cc_external_rule_impl.
|
||||
|
||||
Args:
|
||||
workspace_name: current workspace name
|
||||
generator: The generator target for cmake to use
|
||||
cmake_path: The path to the cmake executable
|
||||
tools: cc_toolchain tools (CxxToolsInfo)
|
||||
flags: cc_toolchain flags (CxxFlagsInfo)
|
||||
|
@ -28,6 +31,7 @@ def create_cmake_script(
|
|||
user_cache: dictionary with user's values of cache initializers
|
||||
user_env: dictionary with user's values for CMake environment variables
|
||||
options: other CMake options specified by user
|
||||
cmake_commands: A list of cmake commands for building and installing targets
|
||||
include_dirs: Optional additional include directories. Defaults to [].
|
||||
is_debug_mode: If the compilation mode is `debug`. Defaults to True.
|
||||
|
||||
|
@ -70,17 +74,35 @@ def create_cmake_script(
|
|||
if not params.cache.get("CMAKE_RANLIB"):
|
||||
params.cache.update({"CMAKE_RANLIB": ""})
|
||||
|
||||
set_env_vars = " ".join([key + "=\"" + params.env[key] + "\"" for key in params.env])
|
||||
script = []
|
||||
|
||||
# Add definitions for all environment variables
|
||||
script.extend(["export {}=\"{}\"".format(key, params.env[key]) for key in params.env])
|
||||
|
||||
str_cmake_cache_entries = " ".join(["-D" + key + "=\"" + params.cache[key] + "\"" for key in params.cache])
|
||||
cmake_call = " ".join([
|
||||
set_env_vars,
|
||||
|
||||
directory = "$EXT_BUILD_ROOT/" + root
|
||||
|
||||
script.append("set -x")
|
||||
|
||||
# Configure the CMake generate command
|
||||
script.append(" ".join([
|
||||
cmake_path,
|
||||
str_cmake_cache_entries,
|
||||
" ".join(options),
|
||||
"$EXT_BUILD_ROOT/" + root,
|
||||
# Generator is always set last and will override anything specified by the user
|
||||
"-G '{}'".format(generator),
|
||||
directory,
|
||||
]))
|
||||
|
||||
script.extend(cmake_commands)
|
||||
|
||||
script.extend([
|
||||
"set +x",
|
||||
"",
|
||||
])
|
||||
|
||||
return "\n".join(params.commands + [cmake_call])
|
||||
return "\n".join(params.commands + script)
|
||||
|
||||
def _wipe_empty_values(cache, keys_with_empty_values_in_user_cache):
|
||||
for key in keys_with_empty_values_in_user_cache:
|
||||
|
|
|
@ -24,7 +24,8 @@ def create_configure_script(
|
|||
autogen,
|
||||
autogen_command,
|
||||
autogen_options,
|
||||
autogen_env_vars):
|
||||
autogen_env_vars,
|
||||
make_commands):
|
||||
env_vars_string = get_env_vars(workspace_name, tools, flags, user_vars, deps, inputs)
|
||||
|
||||
ext_build_dirs = inputs.ext_build_dirs
|
||||
|
@ -66,6 +67,11 @@ def create_configure_script(
|
|||
configure = configure_path,
|
||||
user_options = " ".join(user_options),
|
||||
))
|
||||
|
||||
script.append("set -x")
|
||||
script.extend(make_commands)
|
||||
script.append("set +x")
|
||||
|
||||
return "\n".join(script)
|
||||
|
||||
def _get_autogen_env_vars(autogen_env_vars):
|
||||
|
|
|
@ -6,6 +6,11 @@ load("@bazel_skylib//lib:collections.bzl", "collections")
|
|||
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||
load("//foreign_cc:providers.bzl", "ForeignCcArtifact", "ForeignCcDeps")
|
||||
load("//foreign_cc/private:detect_root.bzl", "detect_root", "filter_containing_dirs_from_inputs")
|
||||
load(
|
||||
"//toolchains/native_tools:tool_access.bzl",
|
||||
"get_make_data",
|
||||
"get_ninja_data",
|
||||
)
|
||||
load(
|
||||
":cc_toolchain_util.bzl",
|
||||
"LibrariesToLinkInfo",
|
||||
|
@ -184,6 +189,13 @@ CC_EXTERNAL_RULE_ATTRIBUTES = {
|
|||
doc = "__deprecated__: Use `out_static_libs` instead.",
|
||||
mandatory = False,
|
||||
),
|
||||
"targets": attr.string_list(
|
||||
doc = (
|
||||
"A list of targets with in the foreign build system to produce. An empty string (`\"\"`) will result in " +
|
||||
"a call to the underlying build system with no explicit target set"
|
||||
),
|
||||
mandatory = False,
|
||||
),
|
||||
"tools_deps": attr.label_list(
|
||||
doc = (
|
||||
"Optional tools to be copied into the directory structure. " +
|
||||
|
@ -334,15 +346,12 @@ def cc_external_rule_impl(ctx, attrs):
|
|||
# Prepend the exec root to each $(execpath ) lookup because the working directory will not be the exec root.
|
||||
value = ctx.expand_location(value.replace("$(execpath ", "$$EXT_BUILD_ROOT$$/$(execpath "), data_dependencies),
|
||||
)
|
||||
for key, value in getattr(ctx.attr, "env", {}).items()
|
||||
for key, value in dict(
|
||||
getattr(ctx.attr, "env", {}).items() + getattr(attrs, "env", {}).items(),
|
||||
).items()
|
||||
]
|
||||
|
||||
make_commands = []
|
||||
for line in attrs.make_commands:
|
||||
if line == "make" or line.startswith("make "):
|
||||
make_commands.append(line.replace("make", attrs.make_path, 1))
|
||||
else:
|
||||
make_commands.append(line)
|
||||
make_commands, build_tools = _generate_make_commands(ctx)
|
||||
|
||||
script_lines = [
|
||||
"##echo## \"\"",
|
||||
|
@ -395,7 +404,7 @@ def cc_external_rule_impl(ctx, attrs):
|
|||
],
|
||||
tools = depset(
|
||||
[wrapped_outputs.script_file, wrapped_outputs.wrapper_script_file] + ctx.files.data + ctx.files.tools_deps + ctx.files.additional_tools,
|
||||
transitive = [cc_toolchain.all_files] + [data[DefaultInfo].default_runfiles.files for data in data_dependencies],
|
||||
transitive = [cc_toolchain.all_files] + [data[DefaultInfo].default_runfiles.files for data in data_dependencies] + build_tools,
|
||||
),
|
||||
# TODO: Default to never using the default shell environment to make builds more hermetic. For now, every platform
|
||||
# but MacOS will take the default PATH passed by Bazel, not that from cc_toolchain.
|
||||
|
@ -857,3 +866,30 @@ def _collect_libs(cc_linking):
|
|||
if library:
|
||||
libs.append(library)
|
||||
return collections.uniq(libs)
|
||||
|
||||
def _generate_make_commands(ctx):
|
||||
make_commands = getattr(ctx.attr, "make_commands", [])
|
||||
tools_deps = []
|
||||
|
||||
# Early out if there are no commands set
|
||||
if not make_commands:
|
||||
return make_commands, tools_deps
|
||||
|
||||
if _uses_tool(ctx.attr.make_commands, "make"):
|
||||
make_data = get_make_data(ctx)
|
||||
tools_deps += make_data.deps
|
||||
make_commands = [command.replace("make", make_data.path) for command in make_commands]
|
||||
|
||||
if _uses_tool(ctx.attr.make_commands, "ninja"):
|
||||
ninja_data = get_ninja_data(ctx)
|
||||
tools_deps += ninja_data.deps
|
||||
make_commands = [command.replace("ninja", ninja_data.path) for command in make_commands]
|
||||
|
||||
return make_commands, [tool.files for tool in tools_deps]
|
||||
|
||||
def _uses_tool(make_commands, tool):
|
||||
for command in make_commands:
|
||||
(before, separator, after) = command.partition(" ")
|
||||
if before == tool:
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -20,7 +20,10 @@ def create_make_script(
|
|||
script = pkgconfig_script(ext_build_dirs)
|
||||
|
||||
script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
|
||||
|
||||
script.append("set -x")
|
||||
script.extend(make_commands)
|
||||
script.append("set +x")
|
||||
return "\n".join(script)
|
||||
|
||||
# buildifier: disable=function-docstring-args
|
||||
|
|
|
@ -241,6 +241,7 @@ def _merge_flag_values_no_toolchain_file_test(ctx):
|
|||
|
||||
script = create_cmake_script(
|
||||
"ws",
|
||||
"Unix Makefiles",
|
||||
"cmake",
|
||||
tools,
|
||||
flags,
|
||||
|
@ -250,8 +251,16 @@ def _merge_flag_values_no_toolchain_file_test(ctx):
|
|||
user_cache,
|
||||
user_env,
|
||||
[],
|
||||
cmake_commands = [],
|
||||
)
|
||||
expected = """CC="/usr/bin/gcc" CXX="/usr/bin/gcc" CXXFLAGS="foo=\\"bar\\" -Fbat" cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB="" $EXT_BUILD_ROOT/external/test_rule"""
|
||||
expected = """\
|
||||
export CC="/usr/bin/gcc"
|
||||
export CXX="/usr/bin/gcc"
|
||||
export CXXFLAGS="foo=\\"bar\\" -Fbat"
|
||||
set -x
|
||||
cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB="" -G 'Unix Makefiles' $EXT_BUILD_ROOT/external/test_rule
|
||||
set +x
|
||||
"""
|
||||
asserts.equals(env, expected, script)
|
||||
|
||||
return unittest.end(env)
|
||||
|
@ -281,6 +290,7 @@ def _create_min_cmake_script_no_toolchain_file_test(ctx):
|
|||
|
||||
script = create_cmake_script(
|
||||
"ws",
|
||||
"Ninja",
|
||||
"cmake",
|
||||
tools,
|
||||
flags,
|
||||
|
@ -289,9 +299,19 @@ def _create_min_cmake_script_no_toolchain_file_test(ctx):
|
|||
True,
|
||||
user_cache,
|
||||
user_env,
|
||||
["-GNinja"],
|
||||
["--debug-output", "-Wdev"],
|
||||
cmake_commands = [],
|
||||
)
|
||||
expected = """CC="/usr/bin/gcc" CXX="/usr/bin/gcc" CFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall" CXXFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall" ASMFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall" cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_SHARED_LINKER_FLAGS="-shared -fuse-ld=gold" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=gold -Wl -no-as-needed" -DNOFORTRAN="on" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS;/abc/def" -DCMAKE_RANLIB="" -GNinja $EXT_BUILD_ROOT/external/test_rule"""
|
||||
expected = """\
|
||||
export CC="/usr/bin/gcc"
|
||||
export CXX="/usr/bin/gcc"
|
||||
export CFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall"
|
||||
export CXXFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall"
|
||||
export ASMFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall"
|
||||
set -x
|
||||
cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_SHARED_LINKER_FLAGS="-shared -fuse-ld=gold" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=gold -Wl -no-as-needed" -DNOFORTRAN="on" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS;/abc/def" -DCMAKE_RANLIB="" --debug-output -Wdev -G 'Ninja' $EXT_BUILD_ROOT/external/test_rule
|
||||
set +x
|
||||
"""
|
||||
asserts.equals(env, expected, script)
|
||||
|
||||
return unittest.end(env)
|
||||
|
@ -324,6 +344,7 @@ def _create_min_cmake_script_wipe_toolchain_test(ctx):
|
|||
|
||||
script = create_cmake_script(
|
||||
"ws",
|
||||
"Ninja",
|
||||
"cmake",
|
||||
tools,
|
||||
flags,
|
||||
|
@ -332,9 +353,19 @@ def _create_min_cmake_script_wipe_toolchain_test(ctx):
|
|||
True,
|
||||
user_cache,
|
||||
user_env,
|
||||
["-GNinja"],
|
||||
["--debug-output", "-Wdev"],
|
||||
cmake_commands = [],
|
||||
)
|
||||
expected = """CC="/usr/bin/gcc" CXX="/usr/bin/gcc" CFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall" CXXFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall" ASMFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall" cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=gold -Wl -no-as-needed" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS;/abc/def" -DCMAKE_RANLIB="" -GNinja $EXT_BUILD_ROOT/external/test_rule"""
|
||||
expected = """\
|
||||
export CC="/usr/bin/gcc"
|
||||
export CXX="/usr/bin/gcc"
|
||||
export CFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall"
|
||||
export CXXFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall"
|
||||
export ASMFLAGS="-U_FORTIFY_SOURCE -fstack-protector -Wall"
|
||||
set -x
|
||||
cmake -DCMAKE_AR="/usr/bin/ar" -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=gold -Wl -no-as-needed" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS;/abc/def" -DCMAKE_RANLIB="" --debug-output -Wdev -G 'Ninja' $EXT_BUILD_ROOT/external/test_rule
|
||||
set +x
|
||||
"""
|
||||
asserts.equals(env, expected, script)
|
||||
|
||||
return unittest.end(env)
|
||||
|
@ -363,6 +394,7 @@ def _create_min_cmake_script_toolchain_file_test(ctx):
|
|||
|
||||
script = create_cmake_script(
|
||||
"ws",
|
||||
"Ninja",
|
||||
"cmake",
|
||||
tools,
|
||||
flags,
|
||||
|
@ -371,7 +403,8 @@ def _create_min_cmake_script_toolchain_file_test(ctx):
|
|||
False,
|
||||
user_cache,
|
||||
user_env,
|
||||
["-GNinja"],
|
||||
["--debug-output", "-Wdev"],
|
||||
cmake_commands = [],
|
||||
)
|
||||
expected = """cat > crosstool_bazel.cmake <<EOF
|
||||
set(CMAKE_AR "/usr/bin/ar" CACHE FILEPATH "Archiver")
|
||||
|
@ -384,7 +417,10 @@ set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=gold -Wl -no-as-needed")
|
|||
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-shared -fuse-ld=gold")
|
||||
EOF
|
||||
|
||||
cmake -DNOFORTRAN="on" -DCMAKE_TOOLCHAIN_FILE="crosstool_bazel.cmake" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule"""
|
||||
set -x
|
||||
cmake -DNOFORTRAN="on" -DCMAKE_TOOLCHAIN_FILE="crosstool_bazel.cmake" -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB=\"\" --debug-output -Wdev -G 'Ninja' $EXT_BUILD_ROOT/external/test_rule
|
||||
set +x
|
||||
"""
|
||||
asserts.equals(env, expected.splitlines(), script.splitlines())
|
||||
|
||||
return unittest.end(env)
|
||||
|
@ -427,6 +463,7 @@ def _create_cmake_script_no_toolchain_file_test(ctx):
|
|||
|
||||
script = create_cmake_script(
|
||||
"ws",
|
||||
"Ninja",
|
||||
"cmake",
|
||||
tools,
|
||||
flags,
|
||||
|
@ -435,9 +472,20 @@ def _create_cmake_script_no_toolchain_file_test(ctx):
|
|||
True,
|
||||
user_cache,
|
||||
user_env,
|
||||
["-GNinja"],
|
||||
["--debug-output", "-Wdev"],
|
||||
cmake_commands = [],
|
||||
)
|
||||
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" -DCMAKE_BUILD_TYPE="user_type" -DCUSTOM_CACHE="YES" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB="" -GNinja $EXT_BUILD_ROOT/external/test_rule"""
|
||||
expected = """\
|
||||
export CC="sink-cc-value"
|
||||
export CXX="sink-cxx-value"
|
||||
export CFLAGS="-cc-flag -gcc_toolchain cc-toolchain --from-env --additional-flag"
|
||||
export CXXFLAGS="--quoted=\\"abc def\\" --sysroot=/abc/sysroot --gcc_toolchain cxx-toolchain"
|
||||
export ASMFLAGS="assemble assemble-user"
|
||||
export CUSTOM_ENV="YES"
|
||||
set -x
|
||||
cmake -DCMAKE_AR="/cxx_linker_static" -DCMAKE_CXX_LINK_EXECUTABLE="became" -DCMAKE_SHARED_LINKER_FLAGS="shared1 shared2" -DCMAKE_EXE_LINKER_FLAGS="executable" -DCMAKE_BUILD_TYPE="user_type" -DCUSTOM_CACHE="YES" -DCMAKE_INSTALL_PREFIX="test_rule" -DCMAKE_PREFIX_PATH="$EXT_BUILD_DEPS" -DCMAKE_RANLIB="" --debug-output -Wdev -G 'Ninja' $EXT_BUILD_ROOT/external/test_rule
|
||||
set +x
|
||||
"""
|
||||
asserts.equals(env, expected, script)
|
||||
|
||||
return unittest.end(env)
|
||||
|
@ -479,6 +527,7 @@ def _create_cmake_script_toolchain_file_test(ctx):
|
|||
|
||||
script = create_cmake_script(
|
||||
"ws",
|
||||
"Ninja",
|
||||
"cmake",
|
||||
tools,
|
||||
flags,
|
||||
|
@ -487,7 +536,8 @@ def _create_cmake_script_toolchain_file_test(ctx):
|
|||
False,
|
||||
user_cache,
|
||||
user_env,
|
||||
["-GNinja"],
|
||||
["--debug-output", "-Wdev"],
|
||||
cmake_commands = [],
|
||||
)
|
||||
expected = """cat > crosstool_bazel.cmake <<EOF
|
||||
set(CMAKE_AR "/cxx_linker_static" CACHE FILEPATH "Archiver")
|
||||
|
@ -504,7 +554,11 @@ set(CMAKE_SHARED_LINKER_FLAGS_INIT "shared1 shared2")
|
|||
set(CMAKE_SYSROOT "/abc/sysroot")
|
||||
EOF
|
||||
|
||||
CUSTOM_ENV=\"YES\" cmake -DCUSTOM_CACHE=\"YES\" -DCMAKE_TOOLCHAIN_FILE=\"crosstool_bazel.cmake\" -DCMAKE_BUILD_TYPE=\"Debug\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_RANLIB=\"\" -GNinja $EXT_BUILD_ROOT/external/test_rule"""
|
||||
export CUSTOM_ENV=\"YES\"
|
||||
set -x
|
||||
cmake -DCUSTOM_CACHE=\"YES\" -DCMAKE_TOOLCHAIN_FILE=\"crosstool_bazel.cmake\" -DCMAKE_BUILD_TYPE=\"Debug\" -DCMAKE_INSTALL_PREFIX=\"test_rule\" -DCMAKE_PREFIX_PATH=\"$EXT_BUILD_DEPS\" -DCMAKE_RANLIB=\"\" --debug-output -Wdev -G 'Ninja' $EXT_BUILD_ROOT/external/test_rule
|
||||
set +x
|
||||
"""
|
||||
asserts.equals(env, expected.splitlines(), script.splitlines())
|
||||
|
||||
return unittest.end(env)
|
||||
|
|
Loading…
Reference in New Issue