Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up unused Rust dependencies, eliminate duplicate repository #830

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ http_archive(
urls = ["https://github.com/google/boringssl/tarball/f7cf966f3ddc6923104f6a354bf0ba5c618f3320"],
)

http_archive(
name = "com_cloudflare_lol_html",
url = "https://github.com/cloudflare/lol-html/tarball/a0053299f6809c2fa4e3af35a4f64bd8069952ba",
strip_prefix = "cloudflare-lol-html-a005329",
type = "tgz",
sha256 = "eba5f6ce291bc0f8e1ba588573c5e88a6a1ba4264b7961b1a674fdbe334b50c2",
build_file = "//:build/BUILD.lol-html",
)

http_archive(
name = "sqlite3",
url = "https://sqlite.org/2022/sqlite-amalgamation-3400100.zip",
Expand Down Expand Up @@ -128,6 +119,9 @@ http_archive(
# Rust bootstrap
#
# workerd uses some Rust libraries, especially lolhtml for implementing HtmlRewriter.
# Note that lol_html itself is not included here to avoid dependency duplication and simplify
# the build process. To update the dependency, update the reference commit in
# rust-deps/BUILD.bazel and run `bazel run //rust-deps:crates_vendor -- --repin`

http_file(
name = "cargo_bazel_linux_x64",
Expand Down Expand Up @@ -200,10 +194,6 @@ load("//rust-deps/crates:crates.bzl", "crate_repositories")

crate_repositories()

load("//rust-deps/cxxbridge_crates:crates.bzl", cxxbridge_repositories = "crate_repositories")

cxxbridge_repositories()

load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies")

rust_analyzer_dependencies()
Expand Down Expand Up @@ -351,3 +341,15 @@ new_local_repository(
visibility = ["//visibility:public"])""",
path = "empty",
)

# rust-based lolhtml dependency, including the API header. See rust-deps for details.
new_local_repository(
name = "com_cloudflare_lol_html",
build_file_content = """cc_library(
name = "lolhtml",
hdrs = ["@workerd//rust-deps:lol_html_api"],
deps = ["@workerd//rust-deps"],
strip_include_prefix = "/",
visibility = ["//visibility:public"],)""",
path = "empty",
)
8 changes: 0 additions & 8 deletions build/BUILD.lol-html

This file was deleted.

66 changes: 0 additions & 66 deletions build/rust_cxx_bridge.bzl

This file was deleted.

105 changes: 16 additions & 89 deletions rust-deps/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("//:build/rust_cxx_bridge.bzl", "rust_cxx_bridge", "rust_cxx_include")
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
load("@rules_rust//rust:defs.bzl", "rust_static_library")
load("@bazel_skylib//lib:selects.bzl", "selects")
Expand Down Expand Up @@ -46,21 +45,17 @@ CARGO_BAZEL = select({
":win_x64": "@cargo_bazel_win_x64//file:downloaded.exe",
})

# TODO (before prod):
# - arm64 build
# - Move lolhtml back to submodule so update-deps works

# Generates a repository containing all the crates we reference from our
# rust workspace
# To repin crates: bazel run //rust-deps:crates_vendor -- --repin
crates_vendor(
name = "crates_vendor",
annotations = {
"lolhtml": [crate.annotation(
shallow_since = "1657163695 -0400",
shallow_since = "1686149015 +0100",
)],
"lol_html": [crate.annotation(
shallow_since = "1657163695 -0400",
shallow_since = "1686149015 +0100",
)],
},
cargo_bazel = CARGO_BAZEL,
Expand All @@ -70,13 +65,6 @@ crates_vendor(
features = ["default"],
version = "1",
),
"cxx": crate.spec(
features = ["default"],
version = "1",
),
"typed-arena": crate.spec(
version = "2",
),
"libc": crate.spec(
version = "0.2",
),
Expand All @@ -91,25 +79,9 @@ crates_vendor(
],
version = "0.14",
),
"object": crate.spec(
default_features = False,
# Only need to be able to read ELF files.
features = [
"std",
"read_core",
"elf",
"archive",
"compression",
"unaligned",
],
version = "0.23",
),
"backtrace": crate.spec(
version = "0.3",
),
"lolhtml": crate.spec(
git = "https://github.com/cloudflare/lol-html.git",
rev = "a0053299f6809c2fa4e3af35a4f64bd8069952ba",
rev = "2681dcf0b3e6907111565199df8c43cc9aab7fe8",
),

# Used for RTTI parameter extraction
Expand Down Expand Up @@ -144,74 +116,29 @@ crates_vendor(
],
)

# To repin crates: bazel run //rust-deps:cxxbridge_vendor -- --repin
crates_vendor(
name = "cxxbridge_vendor",
cargo_bazel = CARGO_BAZEL,
mode = "remote",
packages = {
"cxxbridge-cmd": crate.spec(
version = "1.0.72",
),
},
# host toolchain only
supported_platform_triples = [
"aarch64-apple-darwin",
"x86_64-apple-darwin",
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-gnu",
],
vendor_path = "cxxbridge_crates",
)

rust_cxx_include(
name = "cxx/include",
include_prefix = "rust",
visibility = ["//visibility:public"],
)

rust_cxx_bridge(
name = "addr2line",
src = "src/addr2line.rs",
include_prefix = "workerd/rust",
strip_include_prefix = "src",
visibility = ["//visibility:public"],
)

rust_cxx_bridge(
name = "util",
src = "src/util.rs",
include_prefix = "workerd/rust",
strip_include_prefix = "src",
visibility = ["//visibility:public"],
)

rust_static_library(
name = "rust-deps",
srcs = glob(["**/*.rs"]),
srcs = ["src/lib.rs"],
stamp = -1, # default to bazel --stamp flag
# When stamping is enabled this will be replaced by the corresponding
# value in ./bazel-out/volatile-status.txt
rustc_env = {
"WORKERD_VERSION": "{WORKERD_VERSION}"
},
visibility = ["//visibility:public"],
deps = select({
deps = [
# On Windows, CXX is broken under Bazel (https://github.com/dtolnay/cxx/pull/125).
# Luckily, util.rs and addr2line.rs are only used in the internal build which just targets
# Linux, so we can safely disable compilation of any CXX-using code.
"@platforms//os:windows": ["@crates_vendor//:lolhtml"],
"//conditions:default": [
":addr2line",
":util",
"@crates_vendor//:addr2line",
"@crates_vendor//:anyhow",
"@crates_vendor//:backtrace",
"@crates_vendor//:cxx",
"@crates_vendor//:libc",
"@crates_vendor//:lolhtml",
"@crates_vendor//:object",
"@crates_vendor//:typed-arena",
]
}),
"@crates_vendor//:lolhtml",
],
)

# define the path to the lolhtml headers, this is clunky but allows us to avoid cloning the
# repository twice.
alias(
name = "lol_html_api",
actual = "@crates_vendor__lol_html-1.0.1//:c-api/include/lol_html.h",
tags = ["manual"],
visibility = ["//visibility:public"],
)
Loading