Updated `rules_foreign_cc` version for examples (#895)

* Updated rules_foreign_cc to version 0.5.1

* Enabled `@examples//sys/...` targets
This commit is contained in:
UebelAndre 2021-08-18 06:38:36 -07:00 committed by GitHub
parent ed0c6e9dbf
commit e21071abc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 196 additions and 126 deletions

View File

@ -172,7 +172,6 @@ tasks:
- "-//ffi/rust_calling_c:matrix_dylib_test"
- "-//ffi/rust_calling_c:matrix_dynamically_linked"
- "-//ffi/rust_calling_c/simple/..."
- "-//sys/..."
- "-//proto/..."
- "-//wasm/..."
# rust_doc_test targets are currently broken on windows
@ -228,7 +227,6 @@ tasks:
- "//..."
# TODO: There are windows specific build issues in the generated
# dependencies. This should be fixed and all testing enabled.
- "-//has_aliased_deps/..."
- "-//uses_proc_macro/..."
- "-//uses_sys_crate/..."
build_targets: *crate_universe_windows_targets

View File

@ -64,12 +64,12 @@ node_repositories()
http_archive(
name = "rules_foreign_cc",
sha256 = "3c6445404e9e5d17fa0ecdef61be00dd93b20222c11f45e146a98c0a3f67defa",
strip_prefix = "rules_foreign_cc-d54c78ab86b40770ee19f0949db9d74a831ab9f0",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/d54c78ab86b40770ee19f0949db9d74a831ab9f0.zip",
sha256 = "33a5690733c5cc2ede39cb62ebf89e751f2448e27f20c8b2fbbc7d136b166804",
strip_prefix = "rules_foreign_cc-0.5.1",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.5.1.tar.gz",
)
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()

View File

@ -5,6 +5,11 @@ local_repository(
path = "../..",
)
local_repository(
name = "examples",
path = "../",
)
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()
@ -67,9 +72,9 @@ rbe_autoconfig(name = "buildkite_config")
http_archive(
name = "rules_foreign_cc",
sha256 = "d39b6930a21aed518bf5403dbf333fff731de6314bd0d528f4df62366350a312",
strip_prefix = "rules_foreign_cc-98c88de5e0f57dd2a896dd595469ccd6bf97ceab",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/98c88de5e0f57dd2a896dd595469ccd6bf97ceab.tar.gz",
sha256 = "33a5690733c5cc2ede39cb62ebf89e751f2448e27f20c8b2fbbc7d136b166804",
strip_prefix = "rules_foreign_cc-0.5.1",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.5.1.tar.gz",
)
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

View File

@ -14,6 +14,7 @@ def deps():
supported_targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
],
resolver = "@rules_rust_crate_universe_bootstrap//:crate_universe_resolver",
)

View File

@ -1,58 +0,0 @@
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")
config_setting(
name = "darwin",
values = {"cpu": "darwin"},
visibility = ["//visibility:public"],
)
config_setting(
name = "linux",
values = {"cpu": "k8"},
visibility = ["//visibility:public"],
)
filegroup(
name = "srcs",
srcs = glob(
["**"],
exclude = ["BUILD.bazel"],
),
)
configure_make(
name = "openssl",
configure_command = "config",
configure_env_vars = select({
# On Darwin, the cc_toolchain uses libtool instead of ar, but these do not take compatible arguments.
# By default it will set AR to point at libtool.
# So set AR to an empty value so that Darwin falls back to the system-default ar instead.
":darwin": {
"AR": "",
},
":linux": {},
}),
lib_source = ":srcs",
out_shared_libs = select({
":darwin": [
"libcrypto.dylib",
"libssl.dylib",
],
":linux": [
"libcrypto.so",
"libssl.so",
],
}),
out_static_libs = [
"libcrypto.a",
"libssl.a",
],
visibility = ["//visibility:public"],
)
filegroup(
name = "gen_dir",
srcs = [":openssl"],
output_group = "gen_dir",
visibility = ["//visibility:public"],
)

View File

@ -1,18 +1,10 @@
"""A module for loading crate universe dependencies"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@examples//third_party/openssl:openssl_repositories.bzl", "openssl_repositories")
load("@rules_rust//crate_universe:defs.bzl", "crate", "crate_universe")
def deps():
maybe(
http_archive,
name = "openssl",
build_file = "//has_aliased_deps:BUILD.openssl.bazel",
sha256 = "23011a5cc78e53d0dc98dfa608c51e72bcd350aa57df74c5d5574ba4ffb62e74",
strip_prefix = "openssl-OpenSSL_1_1_1d",
urls = ["https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz"],
)
openssl_repositories()
crate_universe(
name = "has_aliased_deps_deps",
@ -21,6 +13,7 @@ def deps():
"openssl-sys": crate.override(
extra_build_script_env_vars = {
"OPENSSL_DIR": "$(execpath @openssl//:gen_dir)",
"OPENSSL_STATIC": "1",
},
extra_bazel_deps = {
"cfg(all())": ["@openssl//:openssl"],
@ -31,11 +24,18 @@ def deps():
"@openssl//:gen_dir",
],
},
extra_bazel_data_deps = {
"cfg(all())": [
"@openssl//:openssl",
"@openssl//:gen_dir",
],
},
),
},
supported_targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-msvc",
],
resolver = "@rules_rust_crate_universe_bootstrap//:crate_universe_resolver",
)

View File

@ -1,18 +1,10 @@
# buildifier: disable=module-docstring
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//sys/complex/raze:crates.bzl", "complex_sys_fetch_remote_crates")
load("//third_party/openssl:openssl_repositories.bzl", "openssl_repositories")
def complex_sys_repositories():
"""Define repository dependencies for the `complex_sys` example"""
complex_sys_fetch_remote_crates()
maybe(
http_archive,
name = "openssl",
strip_prefix = "openssl-OpenSSL_1_1_1d",
urls = ["https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz"],
sha256 = "23011a5cc78e53d0dc98dfa608c51e72bcd350aa57df74c5d5574ba4ffb62e74",
build_file = "@examples//third_party/openssl:BUILD.openssl.bazel",
)
openssl_repositories()

View File

@ -0,0 +1,11 @@
# The code here was picked up from the `rules_foreign_cc` openssl example
# https://github.com/bazelbuild/rules_foreign_cc/tree/0.5.1/examples/third_party/openssl
exports_files(
[
"BUILD.nasm.bazel",
"BUILD.openssl.bazel",
"BUILD.perl.bazel",
],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,17 @@
# The code here was picked up from the `rules_foreign_cc` openssl example
# https://github.com/bazelbuild/rules_foreign_cc/tree/0.5.1/examples/third_party/openssl
load("@bazel_skylib//rules:select_file.bzl", "select_file")
package(default_visibility = ["//visibility:public"])
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
select_file(
name = "nasm",
srcs = ":all_srcs",
subpath = "nasm.exe",
)

View File

@ -1,53 +1,95 @@
load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
# The code here was picked up from the `rules_foreign_cc` openssl example
# https://github.com/bazelbuild/rules_foreign_cc/tree/0.5.1/examples/third_party/openssl
config_setting(
name = "darwin",
values = {"cpu": "darwin"},
visibility = ["//visibility:public"],
)
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make", "configure_make_variant")
config_setting(
name = "linux",
values = {"cpu": "k8"},
visibility = ["//visibility:public"],
)
# Read https://wiki.openssl.org/index.php/Compilation_and_Installation
filegroup(
name = "srcs",
srcs = glob(
["**"],
exclude = ["BUILD.bazel"],
),
name = "all_srcs",
srcs = glob(["**"]),
)
CONFIGURE_OPTIONS = [
"no-comp",
"no-idea",
"no-weak-ssl-ciphers",
"no-shared",
]
LIB_NAME = "openssl"
MAKE_TARGETS = [
"build_libs",
"install_dev",
]
config_setting(
name = "msvc_compiler",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "msvc-cl",
},
visibility = ["//visibility:public"],
)
alias(
name = "openssl",
actual = select({
":msvc_compiler": "openssl_msvc",
"//conditions:default": "openssl_default",
}),
visibility = ["//visibility:public"],
)
configure_make_variant(
name = "openssl_msvc",
build_data = [
"@nasm_windows//:nasm",
"@perl_windows//:perl",
],
configure_command = "Configure",
configure_in_place = True,
configure_options = CONFIGURE_OPTIONS + [
"VC-WIN64A",
# Unset Microsoft Assembler (MASM) flags set by built-in MSVC toolchain,
# as NASM is unsed to build OpenSSL rather than MASM
"ASFLAGS=\" \"",
],
configure_prefix = "$PERL",
env = {
# The Zi flag must be set otherwise OpenSSL fails to build due to missing .pdb files
"CFLAGS": "-Zi",
"PATH": "$(dirname $(execpath @nasm_windows//:nasm)):$PATH",
"PERL": "$(execpath @perl_windows//:perl)",
},
lib_name = LIB_NAME,
lib_source = ":all_srcs",
out_static_libs = [
"libssl.lib",
"libcrypto.lib",
],
targets = MAKE_TARGETS,
toolchain = "@rules_foreign_cc//toolchains:preinstalled_nmake_toolchain",
)
configure_make(
name = "openssl",
name = "openssl_default",
configure_command = "config",
configure_env_vars = select({
# On Darwin, the cc_toolchain uses libtool instead of ar, but these do not take compatible arguments.
# By default it will set AR to point at libtool.
# So set AR to an empty value so that Darwin falls back to the system-default ar instead.
":darwin": {
"AR": "",
},
":linux": {},
configure_in_place = True,
configure_options = CONFIGURE_OPTIONS,
env = select({
"@platforms//os:macos": {"AR": ""},
"//conditions:default": {},
}),
lib_source = ":srcs",
shared_libraries = select({
":darwin": [
"libcrypto.dylib",
"libssl.dylib",
],
":linux": [
"libcrypto.so",
"libssl.so",
],
}),
static_libraries = [
"libcrypto.a",
lib_name = LIB_NAME,
lib_source = ":all_srcs",
# Note that for Linux builds, libssl must come before libcrypto on the linker command-line.
# As such, libssl must be listed before libcrypto
out_static_libs = [
"libssl.a",
"libcrypto.a",
],
visibility = ["//visibility:public"],
targets = MAKE_TARGETS,
)
filegroup(

View File

@ -0,0 +1,17 @@
# The code here was picked up from the `rules_foreign_cc` openssl example
# https://github.com/bazelbuild/rules_foreign_cc/tree/0.5.1/examples/third_party/openssl
load("@bazel_skylib//rules:select_file.bzl", "select_file")
package(default_visibility = ["//visibility:public"])
filegroup(
name = "all_srcs",
srcs = glob(["**"]),
)
select_file(
name = "perl",
srcs = ":all_srcs",
subpath = "perl/bin/perl.exe",
)

View File

@ -0,0 +1,45 @@
"""A module defining the third party dependency OpenSSL
The code here was picked up from the `rules_foreign_cc` openssl example
https://github.com/bazelbuild/rules_foreign_cc/tree/0.5.1/examples/third_party/openssl
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
def openssl_repositories():
maybe(
http_archive,
name = "openssl",
build_file = Label("//third_party/openssl:BUILD.openssl.bazel"),
sha256 = "892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5",
strip_prefix = "openssl-1.1.1k",
urls = [
"https://mirror.bazel.build/www.openssl.org/source/openssl-1.1.1k.tar.gz",
"https://www.openssl.org/source/openssl-1.1.1k.tar.gz",
"https://github.com/openssl/openssl/archive/OpenSSL_1_1_1k.tar.gz",
],
)
maybe(
http_archive,
name = "nasm_windows",
build_file = Label("//third_party/openssl:BUILD.nasm.bazel"),
sha256 = "f5c93c146f52b4f1664fa3ce6579f961a910e869ab0dae431bd871bdd2584ef2",
strip_prefix = "nasm-2.15.05",
urls = [
"https://mirror.bazel.build/www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip",
"https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/win64/nasm-2.15.05-win64.zip",
],
)
maybe(
http_archive,
name = "perl_windows",
build_file = Label("//third_party/openssl:BUILD.perl.bazel"),
sha256 = "aeb973da474f14210d3e1a1f942dcf779e2ae7e71e4c535e6c53ebabe632cc98",
urls = [
"https://mirror.bazel.build/strawberryperl.com/download/5.32.1.1/strawberry-perl-5.32.1.1-64bit.zip",
"https://strawberryperl.com/download/5.32.1.1/strawberry-perl-5.32.1.1-64bit.zip",
],
)