Skip to content

Commit

Permalink
Replaced crates_universe rule with crates_repository (#1158)
Browse files Browse the repository at this point in the history
* Added unmodified `cargo-bazel` source code

* Applied `rules_rust` specific updates to `cargo-bazel` impl

* Updated lockfiles

* Replaced `crate_universe` examples with `crates_repository` examples

* Applied `rules_rust` specific updates to `cargo-bazel` examples

* Updated examples lockfiles

* Updated `crate_universe` docs to represent `crates_repository`

* Regenerate documentation
  • Loading branch information
UebelAndre committed Mar 3, 2022
1 parent acca6f4 commit 59fab4e
Show file tree
Hide file tree
Showing 659 changed files with 118,962 additions and 7,668 deletions.
36 changes: 16 additions & 20 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ default_windows_targets: &default_windows_targets
- "-//test/proto/..."
- "-//tools/rust_analyzer/..."
- "-//test/rustfmt/..."
crate_universe_vendor_example_targets: &crate_universe_vendor_example_targets
- "//vendor_local_manifests:crates_vendor"
- "//vendor_local_pkgs:crates_vendor"
- "//vendor_remote_manifests:crates_vendor_manifests"
- "//vendor_remote_pkgs:crates_vendor_pkgs"
tasks:
ubuntu2004:
build_targets: *default_linux_targets
Expand Down Expand Up @@ -249,9 +254,8 @@ tasks:
crate_universe_examples_ubuntu2004:
name: Crate Universe Examples
platform: ubuntu2004
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
run_targets: *crate_universe_vendor_example_targets
build_targets:
- "//..."
test_targets:
Expand All @@ -260,12 +264,11 @@ tasks:
crate_universe_rbe_ubuntu1604:
name: Crate Universe Examples
platform: rbe_ubuntu1604
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
shell_commands:
- sed -i 's/^# load("@bazelci_rules/load("@bazelci_rules/' WORKSPACE.bazel
- sed -i 's/^# rbe_preconfig/rbe_preconfig/' WORKSPACE.bazel
run_targets: *crate_universe_vendor_example_targets
build_targets:
- "//..."
test_targets:
Expand All @@ -274,9 +277,8 @@ tasks:
crate_universe_examples_macos:
name: Crate Universe Examples
platform: macos
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
run_targets: *crate_universe_vendor_example_targets
build_targets:
- "//..."
test_targets:
Expand All @@ -285,22 +287,16 @@ tasks:
crate_universe_examples_windows:
name: Crate Universe Examples
platform: windows
environment:
RULES_RUST_CRATE_UNIVERSE_BOOTSTRAP: true
working_directory: examples/crate_universe
build_flags:
- "--enable_runfiles" # this is not enabled by default on windows and is necessary for the cargo build scripts
- "--config=rustfmt"
- "--config=clippy"
crate_universe_windows_targets: &crate_universe_windows_targets
batch_commands:
- echo startup --windows_enable_symlinks >> user.bazelrc
- echo build --enable_runfiles >> user.bazelrc # this is not enabled by default on windows and is necessary for the cargo build scripts
run_targets: *crate_universe_vendor_example_targets
build_flags: *aspects_flags
build_targets:
- "//..."
test_targets:
- "//..."
# TODO: There are windows specific build issues in the generated
# dependencies. This should be fixed and all testing enabled.
- "-//uses_proc_macro/..."
- "-//uses_sys_crate/..."
build_targets: *crate_universe_windows_targets
# TODO: fix test targets in `crate_universe_windows_targets`
test_targets: *crate_universe_windows_targets
buildifier:
version: latest
warnings: "all"
4 changes: 4 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ rules_rust_dependencies()

rust_register_toolchains(include_rustc_srcs = True)

load("@rules_rust//crate_universe:crates.bzl", "crate_deps_repository")

crate_deps_repository(bootstrap = True)

load("@rules_rust//proto:repositories.bzl", "rust_proto_repositories")

rust_proto_repositories()
Expand Down
20 changes: 20 additions & 0 deletions crate_universe/3rdparty/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("//crate_universe:crates.bzl", "crate_deps_target")

package(default_visibility = ["//visibility:public"])

crate_deps_target()

filegroup(
name = "distro",
srcs = glob([
"*.bzl",
"*.bazel",
]) + [
"//crate_universe/3rdparty/crates:srcs",
],
)

filegroup(
name = "bzl_srcs",
srcs = glob(["*.bzl"]),
)
277 changes: 277 additions & 0 deletions crate_universe/3rdparty/BUILD.libgit2.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
# This BUILD file was written based off of the `build.rs` script for the Rust
# crate `libgit2-sys`. For more details, see the crate's source:
# https://github.com/rust-lang/git2-rs/tree/libgit2-sys-0.13.0/libgit2-sys

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc:defs.bzl", "cc_library")

[
config_setting(
name = plat,
constraint_values = ["@platforms//os:{}".format(plat)],
)
for plat in [
"macos",
"ios",
"tvos",
"windows",
]
]

# env::var("CARGO_FEATURE_SSH").is_ok()
bool_flag(
name = "ssh",
build_setting_default = False,
)

config_setting(
name = "ssh_setting",
flag_values = {":ssh": "True"},
)

# target.contains("apple")
selects.config_setting_group(
name = "apple",
match_any = [
":macos",
":ios",
":tvos",
],
)

[
config_setting(
name = "cpu_" + cpu,
constraint_values = ["@platforms//cpu:{}".format(cpu)],
)
for cpu in [
"i386",
"x86_32",
]
]

# env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
selects.config_setting_group(
name = "pointer_width_32",
match_any = [
"cpu_i386",
"cpu_x86_32",
],
)

# env::var("CARGO_FEATURE_HTTPS").is_ok()
bool_flag(
name = "https",
build_setting_default = False,
)

config_setting(
name = "https_setting",
flag_values = {":https": "True"},
)

# if https && target.contains("windows")
selects.config_setting_group(
name = "https_windows",
match_all = [
":https_setting",
":windows",
],
)

# if https && target.contains("apple")
selects.config_setting_group(
name = "https_apple",
match_all = [
":https_setting",
":apple",
],
)

cc_library(
name = "http-parser",
srcs = glob(["deps/http-parser/*.c"]),
hdrs = glob(["deps/http-parser/*.h"]),
copts = select({
# Required in `opt` builds to solve the following error
# libpcre.a(pcre_compile.o): requires unsupported dynamic reloc 11; recompile with -fPIC
"@platforms//os:linux": ["-fPIC"],
"//conditions:default": [],
}),
includes = ["deps/http-parser"],
linkstatic = True,
)

cc_library(
name = "pcre",
srcs = glob(["deps/pcre/**/*.c"]),
hdrs = glob(["deps/pcre/**/*.h"]),
copts = select({
# Required in `opt` builds to solve the following error
# libhttp-parser.a(http_parser.o): requires unsupported dynamic reloc 11; recompile with -fPIC
"@platforms//os:linux": ["-fPIC"],
"//conditions:default": [],
}),
defines = [
"HAVE_STDINT_H=1",
"HAVE_MEMMOVE=1",
"NO_RECURSE=1",
"NEWLINE=10",
"POSIX_MALLOC_THRESHOLD=10",
"LINK_SIZE=2",
"PARENS_NEST_LIMIT=250",
"MATCH_LIMIT=10000000",
"MATCH_LIMIT_RECURSION=MATCH_LIMIT",
"MAX_NAME_SIZE=32",
"MAX_NAME_COUNT=10000",
],
includes = ["deps/pcre"],
linkstatic = True,
)

write_file(
name = "configure_features",
out = "include/git2/sys/features.h",
content = [
"#ifndef INCLUDE_features_h",
"#define INCLUDE_features_h",
"#define GIT_THREADS 1",
"#define GIT_TRACE 1",
] +
# !target.contains("android")
select({
"@platforms//os:android": [],
"//conditions:default": ["#define GIT_USE_NSEC 1"],
}) + select({
":apple": ["#define GIT_USE_STAT_MTIMESPEC 1"],
"//conditions:default": ["#define GIT_USE_STAT_MTIM 1"],
}) + select({
":pointer_width_32": ["#define GIT_ARCH_32 1"],
"//conditions:default": ["#define GIT_ARCH_64 1"],
}) + [
"#define GIT_SHA1_COLLISIONDETECT 1",
] + select({
":ssh_setting": ["#define GIT_SSH 1"],
"//conditions:default": [],
}) + select({
":https_apple": [
"#define GIT_HTTPS 1",
"#define GIT_SECURE_TRANSPORT 1",
],
":https_setting": [
"#define GIT_HTTPS 1",
"#define GIT_OPENSSL 1",
],
# target.contains("windows")
":https_windows": [
"#define GIT_HTTPS 1",
"#define GIT_WINHTTP 1",
],
"//conditions:default": [],
}) + select({
":apple": ["#define GIT_USE_ICONV 1"],
"//conditions:default": [],
}) + [
"#endif",
],
)

cc_library(
name = "git2",
srcs = glob(
include = [
"src/*.c",
"src/*.h",
"src/xdiff/*.h",
"src/xdiff/*.c",
"src/transports/*.h",
"src/transports/*.c",
"src/streams/*.h",
"src/streams/*.c",
"src/hash/*.h",
"src/hash/*.c",
],
exclude = [
"src/win32/**",
"src/unix/**",
],
) + select({
"@platforms//os:windows": glob([
"src/win32/**/*.h",
"src/win32/**/*.c",
]),
"//conditions:default": glob([
"src/unix/**/*.h",
"src/unix/**/*.c",
]),
}) + [
"src/allocators/failalloc.c",
"src/allocators/failalloc.h",
"src/allocators/stdalloc.c",
"src/allocators/stdalloc.h",
"src/allocators/win32_leakcheck.c",
"src/allocators/win32_leakcheck.h",
# Use the CollisionDetection SHA1 implementation.
"src/hash/sha1/collisiondetect.h",
"src/hash/sha1/collisiondetect.c",
"src/hash/sha1/sha1dc/sha1.h",
"src/hash/sha1/sha1dc/sha1.c",
"src/hash/sha1/sha1dc/ubc_check.h",
"src/hash/sha1/sha1dc/ubc_check.c",
],
hdrs = glob(["include/**/*.h"]) + [
":configure_features",
],
copts = select({
"@platforms//os:linux": [
"-fvisibility=hidden",
"-fPIC",
"-Wall",
"-std=gnu90",
# On linux, optimization is required to avoid issues with missing (and unused) symbols:
# `liblibgit2.a(pack.pic.o):pack.c:function packfile_open_locked: error: undefined reference to 'fstat'`
#
# Always enabling optimization helps us avoid this though, it does seem unnecessary and this should
# probably be fixed.
"-O3",
],
"@platforms//os:windows": [],
"//conditions:default": [
"-fvisibility=hidden",
"-fPIC",
"-Wall",
"-std=gnu90",
],
}),
defines = [
# Use the CollisionDetection SHA1 implementation.
"SHA1DC_NO_STANDARD_INCLUDES=1",
"SHA1DC_CUSTOM_INCLUDE_SHA1_C=\\\"common.h\\\"",
"SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\\\"common.h\\\"",
# Use the included PCRE regex backend.
"GIT_REGEX_BUILTIN=1",
] + select({
":windows": ["STRSAFE_NO_DEPRECATE"],
"//conditions:default": [],
}),
includes = [
"include",
"src",
],
linkstatic = True,
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = [
":http-parser",
":pcre",
"@zlib",
],
)

alias(
name = "libgit2",
actual = ":git2",
visibility = ["//visibility:public"],
)
Loading

0 comments on commit 59fab4e

Please sign in to comment.