From 5663d884a2589295f006a82c6bf7cd567356d6d5 Mon Sep 17 00:00:00 2001 From: jheaff1 <48310225+jheaff1@users.noreply.github.com> Date: Tue, 22 Jun 2021 16:51:29 +0100 Subject: [PATCH] Provide out_data_dirs attribute (#419) (#622) This change facilitates hermetic python toolchains, as demonstrated by the test added in this commit. --- docs/README.md | 30 ++++++---- docs/cmake.md | 7 ++- docs/configure_make.md | 7 ++- docs/flatten.md | 29 ++++++---- docs/make.md | 3 +- docs/ninja.md | 7 ++- examples/third_party/BUILD.bazel | 3 + examples/third_party/python/BUILD.bazel | 57 +++++++++++++++++++ .../third_party/python/BUILD.python2.bazel | 47 +++++++++++++++ .../third_party/python/BUILD.python3.bazel | 43 ++++++++++++++ examples/third_party/python/python2_test.py | 8 +++ examples/third_party/python/python3_test.py | 8 +++ .../python/python_repositories.bzl | 39 +++++++++++++ examples/third_party/repositories.bzl | 2 + foreign_cc/private/framework.bzl | 11 +++- 15 files changed, 266 insertions(+), 35 deletions(-) create mode 100644 examples/third_party/python/BUILD.bazel create mode 100644 examples/third_party/python/BUILD.python2.bazel create mode 100644 examples/third_party/python/BUILD.python3.bazel create mode 100644 examples/third_party/python/python2_test.py create mode 100644 examples/third_party/python/python3_test.py create mode 100644 examples/third_party/python/python_repositories.bzl diff --git a/docs/README.md b/docs/README.md index b00fd412b..5a0b1110d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,9 +15,9 @@ should be used instead.
 boost_build(name, additional_inputs, additional_tools, alwayslink, bootstrap_options, data, defines,
-            deps, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only,
-            out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
-            postfix_script, tools_deps, user_options)
+            deps, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs,
+            out_headers_only, out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs,
+            out_static_libs, postfix_script, tools_deps, user_options)
 
Rule for building Boost. Invokes bootstrap.sh and then b2 install. @@ -41,6 +41,7 @@ Rule for building Boost. Invokes bootstrap.sh and then b2 install. | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -59,9 +60,9 @@ Rule for building Boost. Invokes bootstrap.sh and then b2 install.
 cmake(name, additional_inputs, additional_tools, alwayslink, build_args, cache_entries, data,
       defines, deps, env, env_vars, generate_args, generate_crosstool_file, install, install_args,
-      lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only, out_include_dir,
-      out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, postfix_script, targets,
-      tools_deps, working_directory)
+      lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
+      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
+      postfix_script, targets, tools_deps, working_directory)
 
Rule for building external library with CMake. @@ -91,6 +92,7 @@ Rule for building external library with CMake. | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -132,8 +134,9 @@ configure_make(name, autogen_options, autoreconf, autoreconf_env_vars, autoreconf_options, configure_command, configure_env_vars, configure_in_place, configure_options, data, defines, deps, env, install_prefix, lib_name, lib_source, linkopts, make_commands, - out_bin_dir, out_binaries, out_headers_only, out_include_dir, out_interface_libs, - out_lib_dir, out_shared_libs, out_static_libs, postfix_script, targets, tools_deps) + out_bin_dir, out_binaries, out_data_dirs, out_headers_only, out_include_dir, + out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, postfix_script, + targets, tools_deps) 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. @@ -173,6 +176,7 @@ Rule for building external libraries with configure-make pattern. Some 'configur | make_commands | Optional make commands. | List of strings | optional | ["make", "make install"] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -190,9 +194,9 @@ Rule for building external libraries with configure-make pattern. Some 'configur
 make(name, additional_inputs, additional_tools, alwayslink, args, data, defines, deps, env,
-     lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only, out_include_dir,
-     out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, postfix_script, targets,
-     tools_deps)
+     lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
+     out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
+     postfix_script, targets, tools_deps)
 
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. @@ -216,6 +220,7 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -272,7 +277,7 @@ Rule for defining the toolchain data of the native tools (cmake, ninja), to be u
 ninja(name, additional_inputs, additional_tools, alwayslink, args, data, defines, deps, directory,
-      env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only,
+      env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
       out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
       postfix_script, targets, tools_deps)
 
@@ -299,6 +304,7 @@ Rule for building external libraries with [Ninja](https://ninja-build.org/). | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | diff --git a/docs/cmake.md b/docs/cmake.md index ced7a9168..ba75d3ddb 100644 --- a/docs/cmake.md +++ b/docs/cmake.md @@ -138,9 +138,9 @@ cmake(
 cmake(name, additional_inputs, additional_tools, alwayslink, build_args, build_data, cache_entries,
       data, defines, deps, env, generate_args, generate_crosstool_file, install, install_args,
-      lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only, out_include_dir,
-      out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, postfix_script, targets,
-      tool_prefix, tools_deps, working_directory)
+      lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
+      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
+      postfix_script, targets, tool_prefix, tools_deps, working_directory)
 
Rule for building external library with CMake. @@ -170,6 +170,7 @@ Rule for building external library with CMake. | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | diff --git a/docs/configure_make.md b/docs/configure_make.md index 4989a0080..1afc3ba99 100644 --- a/docs/configure_make.md +++ b/docs/configure_make.md @@ -13,9 +13,9 @@ configure_make(name, autoconf_options, autogen, autogen_command, autogen_options, autoreconf, autoreconf_options, build_data, configure_command, configure_in_place, configure_options, configure_prefix, data, defines, deps, env, install_prefix, - lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only, - out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, - postfix_script, targets, tool_prefix, tools_deps) + lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, + out_headers_only, out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, + out_static_libs, postfix_script, targets, tool_prefix, tools_deps) 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. @@ -52,6 +52,7 @@ Rule for building external libraries with configure-make pattern. Some 'configur | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | diff --git a/docs/flatten.md b/docs/flatten.md index c2ce380a9..4cdd70e5f 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -22,8 +22,8 @@
 boost_build(name, additional_inputs, additional_tools, alwayslink, bootstrap_options, build_data,
             data, defines, deps, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries,
-            out_headers_only, out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs,
-            out_static_libs, postfix_script, tool_prefix, tools_deps, user_options)
+            out_data_dirs, out_headers_only, out_include_dir, out_interface_libs, out_lib_dir,
+            out_shared_libs, out_static_libs, postfix_script, tool_prefix, tools_deps, user_options)
 
Rule for building Boost. Invokes bootstrap.sh and then b2 install. @@ -48,6 +48,7 @@ Rule for building Boost. Invokes bootstrap.sh and then b2 install. | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -67,9 +68,9 @@ Rule for building Boost. Invokes bootstrap.sh and then b2 install.
 cmake(name, additional_inputs, additional_tools, alwayslink, build_args, build_data, cache_entries,
       data, defines, deps, env, generate_args, generate_crosstool_file, install, install_args,
-      lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only, out_include_dir,
-      out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, postfix_script, targets,
-      tool_prefix, tools_deps, working_directory)
+      lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
+      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
+      postfix_script, targets, tool_prefix, tools_deps, working_directory)
 
Rule for building external library with CMake. @@ -99,6 +100,7 @@ Rule for building external library with CMake. | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -140,9 +142,9 @@ configure_make(name, autoconf_options, autogen, autogen_command, autogen_options, autoreconf, autoreconf_options, build_data, configure_command, configure_in_place, configure_options, configure_prefix, data, defines, deps, env, install_prefix, - lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only, - out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs, - postfix_script, targets, tool_prefix, tools_deps) + lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, + out_headers_only, out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, + out_static_libs, postfix_script, targets, tool_prefix, tools_deps) 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. @@ -179,6 +181,7 @@ Rule for building external libraries with configure-make pattern. Some 'configur | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -197,7 +200,7 @@ Rule for building external libraries with configure-make pattern. Some 'configur
 make(name, additional_inputs, additional_tools, alwayslink, args, build_data, data, defines, deps,
-     env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only,
+     env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
      postfix_script, targets, tool_prefix, tools_deps)
 
@@ -224,6 +227,7 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | @@ -281,9 +285,9 @@ Rule for defining the toolchain data of the native tools (cmake, ninja), to be u
 ninja(name, additional_inputs, additional_tools, alwayslink, args, build_data, data, defines, deps,
-      directory, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only,
-      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
-      postfix_script, targets, tool_prefix, tools_deps)
+      directory, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs,
+      out_headers_only, out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs,
+      out_static_libs, postfix_script, targets, tool_prefix, tools_deps)
 
Rule for building external libraries with [Ninja](https://ninja-build.org/). @@ -309,6 +313,7 @@ Rule for building external libraries with [Ninja](https://ninja-build.org/). | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | diff --git a/docs/make.md b/docs/make.md index 31a965d6e..b0d19b651 100644 --- a/docs/make.md +++ b/docs/make.md @@ -8,7 +8,7 @@ A rule for building projects using the [GNU Make](https://www.gnu.org/software/m
 make(name, additional_inputs, additional_tools, alwayslink, args, build_data, data, defines, deps,
-     env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only,
+     env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs, out_headers_only,
      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
      postfix_script, targets, tool_prefix, tools_deps)
 
@@ -35,6 +35,7 @@ Rule for building external libraries with GNU Make. GNU Make commands (make and | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | diff --git a/docs/ninja.md b/docs/ninja.md index 53621a08a..b16ef38b2 100644 --- a/docs/ninja.md +++ b/docs/ninja.md @@ -8,9 +8,9 @@ A rule for building projects using the [Ninja](https://ninja-build.org/) build t
 ninja(name, additional_inputs, additional_tools, alwayslink, args, build_data, data, defines, deps,
-      directory, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_headers_only,
-      out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs, out_static_libs,
-      postfix_script, targets, tool_prefix, tools_deps)
+      directory, env, lib_name, lib_source, linkopts, out_bin_dir, out_binaries, out_data_dirs,
+      out_headers_only, out_include_dir, out_interface_libs, out_lib_dir, out_shared_libs,
+      out_static_libs, postfix_script, targets, tool_prefix, tools_deps)
 
Rule for building external libraries with [Ninja](https://ninja-build.org/). @@ -36,6 +36,7 @@ Rule for building external libraries with [Ninja](https://ninja-build.org/). | linkopts | Optional link options to be passed up to the dependencies of this library | List of strings | optional | [] | | out_bin_dir | Optional name of the output subdirectory with the binary files, defaults to 'bin'. | String | optional | "bin" | | out_binaries | Optional names of the resulting binaries. | List of strings | optional | [] | +| out_data_dirs | Optional names of additional directories created by the build that should be declared as bazel action outputs | List of strings | optional | [] | | out_headers_only | Flag variable to indicate that the library produces only headers | Boolean | optional | False | | out_include_dir | Optional name of the output subdirectory with the header files, defaults to 'include'. | String | optional | "include" | | out_interface_libs | Optional names of the resulting interface libraries. | List of strings | optional | [] | diff --git a/examples/third_party/BUILD.bazel b/examples/third_party/BUILD.bazel index 8d5952712..113ef3a28 100644 --- a/examples/third_party/BUILD.bazel +++ b/examples/third_party/BUILD.bazel @@ -17,6 +17,7 @@ test_suite( "//libssh2:libssh2_build_test", "//openssl:openssl_build_test", "//pcre:pcre_build_test", + "//python:python_tests", "//sqlite:sqlite_build_test", "//subversion:subversion_build_test", ], @@ -41,6 +42,7 @@ test_suite( "//libssh2:libssh2_build_test", "//openssl:openssl_build_test", "//pcre:pcre_build_test", + "//python:python_tests", # Missing a new enough automake to build #"//sqlite:sqlite_build_test", #"//subversion:subversion_build_test", @@ -64,6 +66,7 @@ test_suite( "//libssh2:libssh2_build_test", "//openssl:openssl_build_test", "//pcre:pcre_build_test", + "//python:python_tests", "//sqlite:sqlite_build_test", "//subversion:subversion_build_test", ], diff --git a/examples/third_party/python/BUILD.bazel b/examples/third_party/python/BUILD.bazel new file mode 100644 index 000000000..c0d4785e0 --- /dev/null +++ b/examples/third_party/python/BUILD.bazel @@ -0,0 +1,57 @@ +load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair", "py_test") + +exports_files( + [ + "BUILD.python2.bazel", + "BUILD.python3.bazel", + ], + visibility = ["//visibility:public"], +) + +py_runtime( + name = "py2_runtime", + files = ["@python2"], + interpreter = "@python2//:python2_bin", + python_version = "PY2", +) + +py_runtime( + name = "py3_runtime", + files = ["@python3"], + interpreter = "@python3//:python3_bin", + python_version = "PY3", +) + +py_runtime_pair( + name = "py_runtime_pair", + py2_runtime = ":py2_runtime", + py3_runtime = ":py3_runtime", +) + +toolchain( + name = "python_toolchain", + toolchain = ":py_runtime_pair", + toolchain_type = "@rules_python//python:toolchain_type", +) + +py_test( + name = "python2_test", + srcs = ["python2_test.py"], + python_version = "PY2", + visibility = ["//:__pkg__"], +) + +py_test( + name = "python3_test", + srcs = ["python3_test.py"], + python_version = "PY3", + visibility = ["//:__pkg__"], +) + +test_suite( + name = "python_tests", + tests = [ + ":python2_test", + ":python3_test", + ], +) diff --git a/examples/third_party/python/BUILD.python2.bazel b/examples/third_party/python/BUILD.python2.bazel new file mode 100644 index 000000000..13cf9df1b --- /dev/null +++ b/examples/third_party/python/BUILD.python2.bazel @@ -0,0 +1,47 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +configure_make( + name = "python2", + build_data = select({ + "@platforms//os:macos": ["@subversion"], + "//conditions:default": [], + }), + configure_options = [ + "CFLAGS='-Dredacted=\"redacted\"'", + "--with-openssl=$EXT_BUILD_DEPS/openssl", + "--with-zlib=$EXT_BUILD_DEPS/zlib", + "--enable-optimizations", + ], + env = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + features = select({ + "@platforms//os:macos": ["-headerpad"], + "//conditions:default": {}, + }), + # rules_foreign_cc defaults the install_prefix to "python". This conflicts with the "python" executable that is generated. + install_prefix = "py_install", + lib_source = ":all_srcs", + out_binaries = [ + "python2.7", + ], + out_data_dirs = ["lib"], + deps = [ + "@openssl", + "@zlib", + ], +) + +filegroup( + name = "python2_bin", + srcs = [":python2"], + output_group = "python2.7", +) diff --git a/examples/third_party/python/BUILD.python3.bazel b/examples/third_party/python/BUILD.python3.bazel new file mode 100644 index 000000000..0fe1f3e42 --- /dev/null +++ b/examples/third_party/python/BUILD.python3.bazel @@ -0,0 +1,43 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "all_srcs", + srcs = glob(["**"]), +) + +configure_make( + name = "python3", + configure_options = [ + "CFLAGS='-Dredacted=\"redacted\"'", + "--with-openssl=$EXT_BUILD_DEPS/openssl", + "--with-zlib=$EXT_BUILD_DEPS/zlib", + "--enable-optimizations", + ], + env = select({ + "@platforms//os:macos": {"AR": ""}, + "//conditions:default": {}, + }), + features = select({ + "@platforms//os:macos": ["-headerpad"], + "//conditions:default": {}, + }), + # rules_foreign_cc defaults the install_prefix to "python". This conflicts with the "python" executable that is generated. + install_prefix = "py_install", + lib_source = ":all_srcs", + out_binaries = [ + "python3.9", + ], + out_data_dirs = ["lib"], + deps = [ + "@openssl", + "@zlib", + ], +) + +filegroup( + name = "python3_bin", + srcs = [":python3"], + output_group = "python3.9", +) diff --git a/examples/third_party/python/python2_test.py b/examples/third_party/python/python2_test.py new file mode 100644 index 000000000..272679219 --- /dev/null +++ b/examples/third_party/python/python2_test.py @@ -0,0 +1,8 @@ + +import sys +import platform + +if __name__ == "__main__": + + assert('python2_test.runfiles/python2/python2/bin/' in sys.executable) + assert(platform.python_version() == "2.7.9") diff --git a/examples/third_party/python/python3_test.py b/examples/third_party/python/python3_test.py new file mode 100644 index 000000000..c97e89a42 --- /dev/null +++ b/examples/third_party/python/python3_test.py @@ -0,0 +1,8 @@ + +import sys +import platform + +if __name__ == "__main__": + + assert('python3_test.runfiles/python3/python3/bin/' in sys.executable) + assert(platform.python_version() == "3.9.3") diff --git a/examples/third_party/python/python_repositories.bzl b/examples/third_party/python/python_repositories.bzl new file mode 100644 index 000000000..ca6a3dd14 --- /dev/null +++ b/examples/third_party/python/python_repositories.bzl @@ -0,0 +1,39 @@ +"""A module defining the third party dependency Python""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +# buildifier: disable=unnamed-macro +def python_repositories(): + maybe( + http_archive, + name = "python2", + build_file = Label("//python:BUILD.python2.bazel"), + strip_prefix = "Python-2.7.9", + urls = [ + "https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz", + ], + sha256 = "c8bba33e66ac3201dabdc556f0ea7cfe6ac11946ec32d357c4c6f9b018c12c5b", + ) + maybe( + http_archive, + name = "python3", + build_file = Label("//python:BUILD.python3.bazel"), + strip_prefix = "Python-3.9.3", + urls = [ + "https://www.python.org/ftp/python/3.9.3/Python-3.9.3.tgz", + ], + sha256 = "3afeb61a45b5a2e6f1c0f621bd8cf925a4ff406099fdb3d8c97b993a5f43d048", + ) + + maybe( + http_archive, + name = "rules_python", + sha256 = "778197e26c5fbeb07ac2a2c5ae405b30f6cb7ad1f5510ea6fdac03bded96cc6f", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz", + "https://github.com/bazelbuild/rules_python/releases/download/0.2.0/rules_python-0.2.0.tar.gz", + ], + ) + + native.register_toolchains("@rules_foreign_cc_examples_third_party//python:python_toolchain") diff --git a/examples/third_party/repositories.bzl b/examples/third_party/repositories.bzl index 4be7cdb32..1a9bc4af2 100644 --- a/examples/third_party/repositories.bzl +++ b/examples/third_party/repositories.bzl @@ -16,6 +16,7 @@ load("//libpng:libpng_repositories.bzl", "libpng_repositories") load("//libssh2:libssh2_repositories.bzl", "libssh2_repositories") load("//openssl:openssl_repositories.bzl", "openssl_repositories") load("//pcre:pcre_repositories.bzl", "pcre_repositories") +load("//python:python_repositories.bzl", "python_repositories") load("//sqlite:sqlite_repositories.bzl", "sqlite_repositories") load("//subversion:subversion_repositories.bzl", "subversion_repositories") load("//zlib:zlib_repositories.bzl", "zlib_repositories") @@ -37,6 +38,7 @@ def repositories(): libssh2_repositories() openssl_repositories() pcre_repositories() + python_repositories() sqlite_repositories() subversion_repositories() zlib_repositories() diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl index e52b234b5..5c15c9fba 100644 --- a/foreign_cc/private/framework.bzl +++ b/foreign_cc/private/framework.bzl @@ -132,6 +132,10 @@ CC_EXTERNAL_RULE_ATTRIBUTES = { doc = "Optional names of the resulting binaries.", mandatory = False, ), + "out_data_dirs": attr.string_list( + doc = "Optional names of additional directories created by the build that should be declared as bazel action outputs", + mandatory = False, + ), "out_headers_only": attr.bool( doc = "Flag variable to indicate that the library produces only headers", mandatory = False, @@ -674,6 +678,7 @@ def _define_outputs(ctx, attrs, lib_name): attr_binaries_libs = attrs.out_binaries attr_headers_only = attrs.out_headers_only attr_interface_libs = attrs.out_interface_libs + attr_out_data_dirs = attrs.out_data_dirs attr_shared_libs = attrs.out_shared_libs attr_static_libs = attrs.out_static_libs @@ -688,6 +693,10 @@ def _define_outputs(ctx, attrs, lib_name): out_include_dir = ctx.actions.declare_directory(lib_name + "/" + attrs.out_include_dir) + out_data_dirs = [] + for dir in attr_out_data_dirs: + out_data_dirs.append(ctx.actions.declare_directory(lib_name + "/" + dir.lstrip("/"))) + out_binary_files = _declare_out(ctx, lib_name, attrs.out_bin_dir, attr_binaries_libs) libraries = LibrariesToLinkInfo( @@ -696,7 +705,7 @@ def _define_outputs(ctx, attrs, lib_name): interface_libraries = _declare_out(ctx, lib_name, attrs.out_lib_dir, attr_interface_libs), ) - declared_outputs = [out_include_dir] + out_binary_files + declared_outputs = [out_include_dir] + out_data_dirs + out_binary_files declared_outputs += libraries.static_libraries declared_outputs += libraries.shared_libraries + libraries.interface_libraries