make framework function work on apple: (#63)
- initialize apple tools on workspace level properly using universal install_ws_dependency() function - pass proper environment variables to the shell script action - pass proper hidden attributes to framework function rules in case of osx os - also, clean up WORKSPACE file putting example repositories into a separate file - correct: repositories needed by framework function itself should be defined in the same single function in workspace_definitions.bzl - unfortunately, it is not possible to move android initialization anywhere from WORKSPACE file
This commit is contained in:
parent
ccec08efd1
commit
a46bef4945
142
WORKSPACE
142
WORKSPACE
|
@ -6,52 +6,6 @@ rules_foreign_cc_dependencies()
|
|||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
|
||||
|
||||
http_archive(
|
||||
name = "libevent",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "libevent-2.1.8-stable",
|
||||
urls = ["https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "zlib",
|
||||
build_file_content = all_content,
|
||||
sha256 = "4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066",
|
||||
strip_prefix = "zlib-1.2.11",
|
||||
urls = [
|
||||
"https://zlib.net/zlib-1.2.11.tar.xz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "libpng",
|
||||
build_file_content = all_content,
|
||||
sha256 = "2f1e960d92ce3b3abd03d06dfec9637dfbd22febf107a536b44f7a47c60659f6",
|
||||
strip_prefix = "libpng-1.6.34",
|
||||
urls = [
|
||||
"http://ftp-osl.osuosl.org/pub/libpng/src/libpng16/libpng-1.6.34.tar.xz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "org_linaro_components_toolchain_gcc_5_3_1",
|
||||
build_file = "framework_example/cmake_cross/compilers/linaro_linux_gcc_5.3.1.BUILD",
|
||||
strip_prefix = "gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf",
|
||||
url = "https://bazel-mirror.storage.googleapis.com/releases.linaro.org/components/toolchain/binaries/latest-5/arm-linux-gnueabihf/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabihf.tar.xz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "bazel_toolchains",
|
||||
sha256 = "259ec05a457bc93aec2aee7e4e67fb4bc1724a183b67baaf5dd6a08be6d6a84a",
|
||||
strip_prefix = "bazel-toolchains-e76b1031eba14c16d72f5837ae7cb7630a2322e2",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/e76b1031eba14c16d72f5837ae7cb7630a2322e2.tar.gz",
|
||||
"https://github.com/bazelbuild/bazel-toolchains/archive/e76b1031eba14c16d72f5837ae7cb7630a2322e2.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
android_sdk_repository(
|
||||
name = "androidsdk",
|
||||
)
|
||||
|
@ -73,98 +27,6 @@ load("@gmaven_rules//:gmaven.bzl", "gmaven_rules")
|
|||
|
||||
gmaven_rules()
|
||||
|
||||
http_archive(
|
||||
name = "freetype",
|
||||
build_file_content = all_content,
|
||||
sha256 = "e6ffba3c8cef93f557d1f767d7bc3dee860ac7a3aaff588a521e081bc36f4c8a",
|
||||
strip_prefix = "freetype-2.9",
|
||||
urls = [
|
||||
"https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.bz2",
|
||||
],
|
||||
)
|
||||
load(":examples_repositories.bzl", "include_examples_repositories")
|
||||
|
||||
http_archive(
|
||||
name = "libgd",
|
||||
build_file_content = all_content,
|
||||
sha256 = "8c302ccbf467faec732f0741a859eef4ecae22fea2d2ab87467be940842bde51",
|
||||
strip_prefix = "libgd-2.2.5",
|
||||
urls = [
|
||||
"https://github.com/libgd/libgd/releases/download/gd-2.2.5/libgd-2.2.5.tar.xz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "pybind11",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "pybind11-2.2.3",
|
||||
url = "https://github.com/pybind/pybind11/archive/v2.2.3.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "ninja_build",
|
||||
build_file_content = all_content,
|
||||
sha256 = "86b8700c3d0880c2b44c2ff67ce42774aaf8c28cbf57725cb881569288c1c6f4",
|
||||
strip_prefix = "ninja-1.8.2",
|
||||
urls = [
|
||||
"https://github.com/ninja-build/ninja/archive/v1.8.2.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "cares",
|
||||
build_file_content = all_content,
|
||||
sha256 = "62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8",
|
||||
strip_prefix = "c-ares-cares-1_14_0",
|
||||
urls = [
|
||||
"https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "nghttp2",
|
||||
build_file_content = all_content,
|
||||
patch_args = ["-p1"],
|
||||
patch_cmds = ["find . -name '*.sh' -exec sed -i.orig '1s|#!/usr/bin/env sh\$|/bin/sh\$|' {} +"],
|
||||
patches = ["//:nghttp2.patch"],
|
||||
strip_prefix = "nghttp2-e5b3f9addd49bca27e2f99c5c65a564eb5c0cf6d",
|
||||
urls = [
|
||||
"https://github.com/nghttp2/nghttp2/archive/e5b3f9addd49bca27e2f99c5c65a564eb5c0cf6d.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "cmake",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "CMake-3.12.1",
|
||||
urls = [
|
||||
"https://github.com/Kitware/CMake/archive/v3.12.1.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
new_http_archive(
|
||||
name = "pcl",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "pcl-pcl-1.8.1",
|
||||
urls = ["https://github.com/PointCloudLibrary/pcl/archive/pcl-1.8.1.tar.gz"],
|
||||
)
|
||||
|
||||
new_http_archive(
|
||||
name = "eigen",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "eigen-git-mirror-3.3.5",
|
||||
urls = ["https://github.com/eigenteam/eigen-git-mirror/archive/3.3.5.tar.gz"],
|
||||
)
|
||||
|
||||
new_http_archive(
|
||||
name = "openblas",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "OpenBLAS-0.3.2",
|
||||
urls = ["https://github.com/xianyi/OpenBLAS/archive/v0.3.2.tar.gz"],
|
||||
)
|
||||
|
||||
new_http_archive(
|
||||
name = "flann",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "flann-1.9.1",
|
||||
urls = ["https://github.com/mariusmuja/flann/archive/1.9.1.tar.gz"],
|
||||
)
|
||||
include_examples_repositories()
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
|
||||
|
||||
def include_examples_repositories():
|
||||
http_archive(
|
||||
name = "libevent",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "libevent-2.1.8-stable",
|
||||
urls = ["https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "zlib",
|
||||
build_file_content = all_content,
|
||||
sha256 = "4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a2114e19bf066",
|
||||
strip_prefix = "zlib-1.2.11",
|
||||
urls = [
|
||||
"https://zlib.net/zlib-1.2.11.tar.xz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "libpng",
|
||||
build_file_content = all_content,
|
||||
sha256 = "2f1e960d92ce3b3abd03d06dfec9637dfbd22febf107a536b44f7a47c60659f6",
|
||||
strip_prefix = "libpng-1.6.34",
|
||||
urls = [
|
||||
"http://ftp-osl.osuosl.org/pub/libpng/src/libpng16/libpng-1.6.34.tar.xz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "freetype",
|
||||
build_file_content = all_content,
|
||||
sha256 = "e6ffba3c8cef93f557d1f767d7bc3dee860ac7a3aaff588a521e081bc36f4c8a",
|
||||
strip_prefix = "freetype-2.9",
|
||||
urls = [
|
||||
"https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.bz2",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "libgd",
|
||||
build_file_content = all_content,
|
||||
sha256 = "8c302ccbf467faec732f0741a859eef4ecae22fea2d2ab87467be940842bde51",
|
||||
strip_prefix = "libgd-2.2.5",
|
||||
urls = [
|
||||
"https://github.com/libgd/libgd/releases/download/gd-2.2.5/libgd-2.2.5.tar.xz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "pybind11",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "pybind11-2.2.3",
|
||||
url = "https://github.com/pybind/pybind11/archive/v2.2.3.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "cares",
|
||||
build_file_content = all_content,
|
||||
sha256 = "62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8",
|
||||
strip_prefix = "c-ares-cares-1_14_0",
|
||||
urls = [
|
||||
"https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "nghttp2",
|
||||
build_file_content = all_content,
|
||||
patch_args = ["-p1"],
|
||||
patch_cmds = ["find . -name '*.sh' -exec sed -i.orig '1s|#!/usr/bin/env sh\$|/bin/sh\$|' {} +"],
|
||||
patches = ["//:nghttp2.patch"],
|
||||
strip_prefix = "nghttp2-e5b3f9addd49bca27e2f99c5c65a564eb5c0cf6d",
|
||||
urls = [
|
||||
"https://github.com/nghttp2/nghttp2/archive/e5b3f9addd49bca27e2f99c5c65a564eb5c0cf6d.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "eigen",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "eigen-git-mirror-3.3.5",
|
||||
urls = ["https://github.com/eigenteam/eigen-git-mirror/archive/3.3.5.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "openblas",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "OpenBLAS-0.3.2",
|
||||
urls = ["https://github.com/xianyi/OpenBLAS/archive/v0.3.2.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "flann",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "flann-1.9.1",
|
||||
urls = ["https://github.com/mariusmuja/flann/archive/1.9.1.tar.gz"],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "pcl",
|
||||
build_file_content = all_content,
|
||||
strip_prefix = "pcl-pcl-1.8.1",
|
||||
urls = ["https://github.com/PointCloudLibrary/pcl/archive/pcl-1.8.1.tar.gz"],
|
||||
)
|
|
@ -0,0 +1,40 @@
|
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
def repositories():
|
||||
_all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
|
||||
|
||||
http_archive(
|
||||
name = "bazel_skylib",
|
||||
build_file_content = _all_content,
|
||||
sha256 = "b5f6abe419da897b7901f90cbab08af958b97a8f3575b0d3dd062ac7ce78541f",
|
||||
strip_prefix = "bazel-skylib-0.5.0",
|
||||
type = "tar.gz",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel-skylib/archive/0.5.0.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "build_bazel_rules_apple",
|
||||
strip_prefix = "rules_apple-0.7.0",
|
||||
url = "https://github.com/bazelbuild/rules_apple/archive/0.7.0.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "ninja_build",
|
||||
build_file_content = _all_content,
|
||||
sha256 = "86b8700c3d0880c2b44c2ff67ce42774aaf8c28cbf57725cb881569288c1c6f4",
|
||||
strip_prefix = "ninja-1.8.2",
|
||||
urls = [
|
||||
"https://github.com/ninja-build/ninja/archive/v1.8.2.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "cmake",
|
||||
build_file_content = _all_content,
|
||||
strip_prefix = "CMake-3.12.1",
|
||||
urls = [
|
||||
"https://github.com/Kitware/CMake/archive/v3.12.1.tar.gz",
|
||||
],
|
||||
)
|
|
@ -165,7 +165,7 @@ def _attrs():
|
|||
"""
|
||||
cmake_external = rule(
|
||||
attrs = _attrs(),
|
||||
fragments = ["cpp"],
|
||||
fragments = ["cpp", "apple"],
|
||||
output_to_genfiles = True,
|
||||
implementation = _cmake_external,
|
||||
)
|
||||
|
|
|
@ -10,6 +10,97 @@ load(
|
|||
"targets_windows",
|
||||
)
|
||||
load("//tools/build_defs:detect_root.bzl", "detect_root")
|
||||
load("@foreign_cc_platform_utils//:host_os.bzl", "host_os")
|
||||
load(
|
||||
"@build_bazel_rules_apple//apple/bundling:platform_support.bzl",
|
||||
"platform_support",
|
||||
)
|
||||
|
||||
def _create_common_attributes():
|
||||
dict = {
|
||||
# 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.
|
||||
"lib_name": attr.string(mandatory = False),
|
||||
# Label with source code to build. Typically a filegroup for the source of remote repository.
|
||||
# Mandatory.
|
||||
"lib_source": attr.label(mandatory = True, allow_files = True),
|
||||
# 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.
|
||||
"defines": attr.string_list(mandatory = False, default = []),
|
||||
#
|
||||
# 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.
|
||||
"additional_inputs": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
# Optional additional tools needed for the building.
|
||||
# Not used by the shell script part in cc_external_rule_impl.
|
||||
"additional_tools": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
#
|
||||
# Optional part of the shell script to be added after the make commands
|
||||
"postfix_script": attr.string(mandatory = False),
|
||||
# Optinal make commands, defaults to ["make", "make install"]
|
||||
"make_commands": attr.string_list(mandatory = False, default = ["make", "make install"]),
|
||||
#
|
||||
# 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)
|
||||
"deps": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
# Optional tools to be copied into the directory structure.
|
||||
# Similar to deps, those directly required for the external building of the library/binaries.
|
||||
"tools_deps": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
#
|
||||
# Optional name of the output subdirectory with the header files, defaults to 'include'.
|
||||
"out_include_dir": attr.string(mandatory = False, default = "include"),
|
||||
# Optional name of the output subdirectory with the library files, defaults to 'lib'.
|
||||
"out_lib_dir": attr.string(mandatory = False, default = "lib"),
|
||||
# Optional name of the output subdirectory with the binary files, defaults to 'bin'.
|
||||
"out_bin_dir": attr.string(mandatory = False, default = "bin"),
|
||||
#
|
||||
# Optional. if true, link all the object files from the static library,
|
||||
# even if they are not used.
|
||||
"alwayslink": attr.bool(mandatory = False, default = False),
|
||||
# Optional link options to be passed up to the dependencies of this library
|
||||
"linkopts": attr.string_list(mandatory = False, default = []),
|
||||
#
|
||||
# Output files names parameters. If any of them is defined, only these files are passed to
|
||||
# Bazel providers.
|
||||
# if no of them is defined, default lib_name.a/lib_name.lib static library is assumed.
|
||||
#
|
||||
# Optional names of the resulting static libraries.
|
||||
"static_libraries": attr.string_list(mandatory = False),
|
||||
# Optional names of the resulting shared libraries.
|
||||
"shared_libraries": attr.string_list(mandatory = False),
|
||||
# Optional names of the resulting interface libraries.
|
||||
"interface_libraries": attr.string_list(mandatory = False),
|
||||
# Optional names of the resulting binaries.
|
||||
"binaries": attr.string_list(mandatory = False),
|
||||
# Flag variable to indicate that the library produces only headers
|
||||
"headers_only": attr.bool(mandatory = False, default = False),
|
||||
#
|
||||
# link to the shell utilities used by the shell script in cc_external_rule_impl.
|
||||
"_utils": attr.label(
|
||||
default = "@foreign_cc_platform_utils//:shell_utils",
|
||||
allow_single_file = True,
|
||||
cfg = "target",
|
||||
),
|
||||
# we need to declare this attribute to access cc_toolchain
|
||||
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
|
||||
}
|
||||
if host_os["is_osx"]:
|
||||
dict.update({
|
||||
"_xcode_config": attr.label(default = Label("@bazel_tools//tools/osx:current_xcode_config")),
|
||||
"_xcrunwrapper": attr.label(
|
||||
executable = True,
|
||||
cfg = "host",
|
||||
default = Label("@bazel_tools//tools/objc:xcrunwrapper"),
|
||||
),
|
||||
"_platform_type": attr.string(
|
||||
default = str(apple_common.platform_type.macos),
|
||||
),
|
||||
})
|
||||
return dict
|
||||
|
||||
""" Dict with definitions of the context attributes, that customize cc_external_rule_impl function.
|
||||
Many of the attributes have default values.
|
||||
|
@ -17,77 +108,7 @@ load("//tools/build_defs:detect_root.bzl", "detect_root")
|
|||
Typically, the concrete external library rule will use this structure to create the attributes
|
||||
description dict. See cmake.bzl as an example.
|
||||
"""
|
||||
CC_EXTERNAL_RULE_ATTRIBUTES = {
|
||||
# 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.
|
||||
"lib_name": attr.string(mandatory = False),
|
||||
# Label with source code to build. Typically a filegroup for the source of remote repository.
|
||||
# Mandatory.
|
||||
"lib_source": attr.label(mandatory = True, allow_files = True),
|
||||
# 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.
|
||||
"defines": attr.string_list(mandatory = False, default = []),
|
||||
#
|
||||
# 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.
|
||||
"additional_inputs": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
# Optional additional tools needed for the building.
|
||||
# Not used by the shell script part in cc_external_rule_impl.
|
||||
"additional_tools": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
#
|
||||
# Optional part of the shell script to be added after the make commands
|
||||
"postfix_script": attr.string(mandatory = False),
|
||||
# Optinal make commands, defaults to ["make", "make install"]
|
||||
"make_commands": attr.string_list(mandatory = False, default = ["make", "make install"]),
|
||||
#
|
||||
# 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)
|
||||
"deps": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
# Optional tools to be copied into the directory structure.
|
||||
# Similar to deps, those directly required for the external building of the library/binaries.
|
||||
"tools_deps": attr.label_list(mandatory = False, allow_files = True, default = []),
|
||||
#
|
||||
# Optional name of the output subdirectory with the header files, defaults to 'include'.
|
||||
"out_include_dir": attr.string(mandatory = False, default = "include"),
|
||||
# Optional name of the output subdirectory with the library files, defaults to 'lib'.
|
||||
"out_lib_dir": attr.string(mandatory = False, default = "lib"),
|
||||
# Optional name of the output subdirectory with the binary files, defaults to 'bin'.
|
||||
"out_bin_dir": attr.string(mandatory = False, default = "bin"),
|
||||
#
|
||||
# Optional. if true, link all the object files from the static library,
|
||||
# even if they are not used.
|
||||
"alwayslink": attr.bool(mandatory = False, default = False),
|
||||
# Optional link options to be passed up to the dependencies of this library
|
||||
"linkopts": attr.string_list(mandatory = False, default = []),
|
||||
#
|
||||
# Output files names parameters. If any of them is defined, only these files are passed to
|
||||
# Bazel providers.
|
||||
# if no of them is defined, default lib_name.a/lib_name.lib static library is assumed.
|
||||
#
|
||||
# Optional names of the resulting static libraries.
|
||||
"static_libraries": attr.string_list(mandatory = False),
|
||||
# Optional names of the resulting shared libraries.
|
||||
"shared_libraries": attr.string_list(mandatory = False),
|
||||
# Optional names of the resulting interface libraries.
|
||||
"interface_libraries": attr.string_list(mandatory = False),
|
||||
# Optional names of the resulting binaries.
|
||||
"binaries": attr.string_list(mandatory = False),
|
||||
# Flag variable to indicate that the library produces only headers
|
||||
"headers_only": attr.bool(mandatory = False, default = False),
|
||||
#
|
||||
# link to the shell utilities used by the shell script in cc_external_rule_impl.
|
||||
"_utils": attr.label(
|
||||
default = "@foreign_cc_platform_utils//:shell_utils",
|
||||
allow_single_file = True,
|
||||
cfg = "target",
|
||||
),
|
||||
# we need to declare this attribute to access cc_toolchain
|
||||
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
|
||||
}
|
||||
CC_EXTERNAL_RULE_ATTRIBUTES = _create_common_attributes()
|
||||
|
||||
def create_attrs(attr_struct, configure_name, configure_script, **kwargs):
|
||||
""" Function for adding/modifying context attributes struct (originally from ctx.attr),
|
||||
|
@ -183,14 +204,23 @@ def cc_external_rule_impl(ctx, attrs):
|
|||
script_text = "\n".join(script_lines)
|
||||
print("script text: " + script_text)
|
||||
|
||||
env = {}
|
||||
execution_requirements = {"block-network": ""}
|
||||
if host_os["is_osx"]:
|
||||
env = _xcrun_env(ctx)
|
||||
execution_requirements.update({
|
||||
"requires-darwin": "",
|
||||
})
|
||||
|
||||
ctx.actions.run_shell(
|
||||
mnemonic = "Cc" + attrs.configure_name.capitalize() + "MakeRule",
|
||||
inputs = depset(inputs.declared_inputs) + ctx.attr._cc_toolchain.files,
|
||||
outputs = outputs.declared_outputs,
|
||||
tools = ctx.attr._utils.files,
|
||||
use_default_shell_env = True,
|
||||
use_default_shell_env = False,
|
||||
command = script_text,
|
||||
execution_requirements = {"block-network": ""},
|
||||
execution_requirements = execution_requirements,
|
||||
env = env,
|
||||
)
|
||||
|
||||
return [
|
||||
|
@ -465,3 +495,10 @@ def _collect_flags(cc_linking):
|
|||
for params in _extract_link_params(cc_linking):
|
||||
linkopts = params.linkopts.to_list()
|
||||
return collections.uniq(linkopts)
|
||||
|
||||
def _xcrun_env(ctx):
|
||||
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
|
||||
|
||||
action_env = apple_common.target_apple_env(xcode_config, platform_support.platform(ctx))
|
||||
action_env.update(apple_common.apple_host_system_env(xcode_config))
|
||||
return action_env
|
||||
|
|
|
@ -1,16 +1,53 @@
|
|||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
|
||||
def _define_shell_utils_impl(rctx):
|
||||
#load("@bazel_tools//tools/osx:xcode_configure.bzl", "xcode_configure")
|
||||
load(":repositories.bzl", "repositories")
|
||||
load(":install_ws_dependency.bzl", "install_ws_dependency")
|
||||
|
||||
def _platform_dependent_init_impl(rctx):
|
||||
host_os = _get_host_os(rctx)
|
||||
rctx.file("WORKSPACE", """workspace(name='foreign_cc_platform_utils')""")
|
||||
rctx.file("BUILD.bazel", "\n".join(
|
||||
[_shell_utils_text(rctx, host_os), _cmake_build_rule_text(rctx, host_os)],
|
||||
))
|
||||
_create_os_description(rctx, host_os)
|
||||
|
||||
# xcode_configure("@bazel_tools//tools/osx:xcode_locator.m")
|
||||
|
||||
def _get_host_os(rctx):
|
||||
os_name = rctx.os.name.lower()
|
||||
is_win = os_name.find("windows") != -1
|
||||
is_osx = os_name.startswith("mac os")
|
||||
return {
|
||||
"is_unix": not is_win and not is_osx,
|
||||
"is_win": is_win,
|
||||
"is_osx": is_osx,
|
||||
}
|
||||
|
||||
def _create_os_description(rctx, host_os):
|
||||
rctx.file("host_os.bzl", "host_os = " + str(host_os) + "\n")
|
||||
|
||||
def _shell_utils_text(rctx, host_os):
|
||||
utils_name = "utils_unix.sh"
|
||||
if os_name.startswith("mac os"):
|
||||
if host_os["is_osx"]:
|
||||
utils_name = "utils_osx.sh"
|
||||
if os_name.find("windows") != -1:
|
||||
if host_os["is_win"]:
|
||||
utils_name = "utils_win.bat"
|
||||
fail("Not supported yet!")
|
||||
|
||||
existing_cmake = rctx.which("cmake")
|
||||
path = rctx.path(Label("//tools/build_defs:" + utils_name))
|
||||
rctx.template(utils_name, path, executable = True)
|
||||
|
||||
return """
|
||||
sh_library(
|
||||
name = "shell_utils",
|
||||
srcs = ["{}"],
|
||||
visibility = ["//visibility:public"]
|
||||
)
|
||||
""".format(utils_name)
|
||||
|
||||
def _cmake_build_rule_text(rctx, host_os):
|
||||
existing_cmake = rctx.which("cmake")
|
||||
is_ci = rctx.os.environ.get("CI")
|
||||
|
||||
cmake_globals_text = ""
|
||||
|
@ -22,13 +59,13 @@ def _define_shell_utils_impl(rctx):
|
|||
cmake_globals_text = """
|
||||
CMAKE_COMMAND="cmake"
|
||||
CMAKE_DEPS=[]
|
||||
"""
|
||||
"""
|
||||
cmake_text = """
|
||||
sh_library(
|
||||
name = "cmake",
|
||||
visibility = ["//visibility:public"]
|
||||
)
|
||||
"""
|
||||
"""
|
||||
else:
|
||||
path_to_cmake_build = rctx.path(Label("//tools/build_defs:cmake_build.bzl"))
|
||||
rctx.template("cmake_build.bzl", path_to_cmake_build)
|
||||
|
@ -40,6 +77,7 @@ sh_library(
|
|||
CMAKE_COMMAND="$EXT_BUILD_DEPS/bin/cmake/bin/cmake"
|
||||
CMAKE_DEPS=[Label("@foreign_cc_platform_utils//:cmake")]
|
||||
"""
|
||||
|
||||
cmake_text = """
|
||||
sh_library(
|
||||
name = "cmake",
|
||||
|
@ -53,38 +91,20 @@ cmake_tool(
|
|||
cmake_srcs = "@cmake//:all"
|
||||
)
|
||||
"""
|
||||
|
||||
rctx.file("cmake_globals.bzl", cmake_globals_text)
|
||||
return cmake_text
|
||||
|
||||
rctx.file("WORKSPACE", """workspace(name='foreign_cc_platform_utils')""")
|
||||
|
||||
rctx.file("BUILD.bazel", """
|
||||
sh_library(
|
||||
name = "shell_utils",
|
||||
srcs = ["{}"],
|
||||
visibility = ["//visibility:public"]
|
||||
)
|
||||
""".format(utils_name) + cmake_text)
|
||||
|
||||
path = rctx.path(Label("//tools/build_defs:" + utils_name))
|
||||
rctx.template(utils_name, path, executable = True)
|
||||
|
||||
_define_shell_utils = repository_rule(
|
||||
implementation = _define_shell_utils_impl,
|
||||
_platform_dependent_init = repository_rule(
|
||||
implementation = _platform_dependent_init_impl,
|
||||
)
|
||||
|
||||
def rules_foreign_cc_dependencies():
|
||||
_all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
|
||||
|
||||
http_archive(
|
||||
name = "bazel_skylib",
|
||||
build_file_content = _all_content,
|
||||
sha256 = "b5f6abe419da897b7901f90cbab08af958b97a8f3575b0d3dd062ac7ce78541f",
|
||||
strip_prefix = "bazel-skylib-0.5.0",
|
||||
type = "tar.gz",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel-skylib/archive/0.5.0.tar.gz",
|
||||
],
|
||||
repositories()
|
||||
_platform_dependent_init(name = "foreign_cc_platform_utils")
|
||||
install_ws_dependency(
|
||||
repo_name = "build_bazel_rules_apple",
|
||||
url = "https://github.com/bazelbuild/rules_apple/archive/0.7.0.tar.gz",
|
||||
strip_prefix = "rules_apple-0.7.0",
|
||||
init_file = "//apple:repositories.bzl",
|
||||
init_function = "apple_rules_dependencies",
|
||||
)
|
||||
|
||||
_define_shell_utils(name = "foreign_cc_platform_utils")
|
||||
|
|
Loading…
Reference in New Issue