Skip to content

Commit

Permalink
feat: adds a partial setup to build rust_icu_sys with bazel
Browse files Browse the repository at this point in the history
This is an experimental change, hopefully will include other crates too.
  • Loading branch information
filmil committed Nov 12, 2024
1 parent a2aef0a commit 304d979
Show file tree
Hide file tree
Showing 10 changed files with 3,601 additions and 68 deletions.
3,395 changes: 3,395 additions & 0 deletions Cargo.Bazel.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ go_deps.from_file(go_mod = "//:go.mod")
use_repo(go_deps)

bazel_dep(name = "rules_foreign_cc", version = "0.10.1")

bazel_dep(name = "toolchains_llvm", version = "1.0.0")

# Configure and register the toolchain.
Expand All @@ -31,7 +30,6 @@ llvm.toolchain(
# work with just any version of LLVM.
llvm_version = "15.0.6",
)

use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all")
6 changes: 3 additions & 3 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 102 additions & 29 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,59 +1,132 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_rust",
sha256 = "36ab8f9facae745c9c9c1b33d225623d976e78f2cc3f729b7973d8c20934ab95",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.31.0/rules_rust-v0.31.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")

rules_rust_dependencies()

rust_register_toolchains(
edition = "2021",
versions = ["1.79.0"],
)

######################################################################

# Use to generate rust-project.json.
# Use bazel run @rules_rust//tools/rust_analyzer:gen_rust_project

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

rust_analyzer_dependencies()

######################################################################

# This is how to generate new lock files. At the project outset, you must
# (1) create the empty files `//third_party/cargo:Cargo.lock`, and
# `//third_party/cargo:Cargo.Bazel.lock`.
# (2) Run `env CARGO_BAZEL_REPI=true bazel build //...` to initialize the
# lockfiles.
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "render_config")

crates_repository(
name = "crate_index",
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:Cargo.Bazel.lock",
packages = {
# Add any other crates you need here.
"bumpalo": crate.spec(
version = "3.6.1",
),
"libc": crate.spec(
version = "0.2.34",
),
"paste": crate.spec(
version = "1.0",
),
"anyhow": crate.spec(
version = "1.0.72",
),
"bindgen": crate.spec(
version = "0.59.2",
),
"lazy_static": crate.spec(
version = "1.4.0",
),
},
render_config = render_config(
default_package_name = "",
),
)

load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

######################################################################

http_archive(
name = "icu_74",
strip_prefix = "icu-release-74-2",
integrity = "sha256-J7hlCpTfb5Rcs7aGvjvjIMKjLt8+zimBZyv5i7O6qeE=",
build_file = "//third_party/icu_74:icu.BUILD.bazel",
urls = [
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.tar.gz",
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.zip",
integrity = "sha256-J7hlCpTfb5Rcs7aGvjvjIMKjLt8+zimBZyv5i7O6qeE=",
patch_args = [
"-p1",
# Without this flag, the bazel build files just get emptied, but not
# removed. This is not enough.
"--remove-empty-files",
],
patches = [
# ICU has a nascent bazel build, which messes up our build based on
# the configure_make rule from rules_foreign_cc. So we remove them.
"//third_party/icu_74:0001-fix-removes-BUILD-files.patch",
],
patch_args = [
"-p1",
# Without this flag, the bazel build files just get emptied, but not
# removed. This is not enough.
"--remove-empty-files",
]
strip_prefix = "icu-release-74-2",
urls = [
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.tar.gz",
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.zip",
],
)

http_archive(
name = "icu_73",
strip_prefix = "icu-release-73-1",
integrity = "sha256-57a1QMiB6D0kC0oSty+8l+9frTDY0A8u9nS6GOO/NkA=",
build_file = "//third_party/icu_73:icu.BUILD.bazel",
urls = [
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.tar.gz",
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.zip",
integrity = "sha256-57a1QMiB6D0kC0oSty+8l+9frTDY0A8u9nS6GOO/NkA=",
patch_args = [
"-p1",
"--remove-empty-files",
],
patches = [
"//third_party/icu_73:0001-fix-removes-BUILD-files.patch",
],
patch_args = [
"-p1",
"--remove-empty-files",
]
strip_prefix = "icu-release-73-1",
urls = [
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.tar.gz",
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.zip",
],
)

http_archive(
name = "icu_72",
strip_prefix = "icu-release-72-1",
integrity = "sha256-Q8utYo2Y83o/lfbDRXn5FE70veYCSPpgBKTwBtdIfmk=",
build_file = "//third_party/icu_72:icu.BUILD.bazel",
urls = [
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.tar.gz",
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.zip",
integrity = "sha256-Q8utYo2Y83o/lfbDRXn5FE70veYCSPpgBKTwBtdIfmk=",
patch_args = [
"-p1",
"--remove-empty-files",
],
patches = [
"//third_party/icu_72:0001-fix-removes-BUILD-files.patch",
],
patch_args = [
"-p1",
"--remove-empty-files",
]
strip_prefix = "icu-release-72-1",
urls = [
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.tar.gz",
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.zip",
],
)
59 changes: 59 additions & 0 deletions rust_icu_sys/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")

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

rust_library(
name = "rust_icu_sys",
srcs = [
"src/lib.rs",
"tests/hygiene.rs",
":macros_rs",
],
crate_name = "rust_icu_sys",
edition = "2021",
proc_macro_deps = [
"@crate_index//:paste",
],
deps = [
"@crate_index//:libc",
":build_script",
"@icu_74//:icu",
],
)

cargo_build_script(
name = "build_script",
srcs = [ "build.rs" ],
crate_features = [
"use-bindgen", "bindgen", "renaming", "icu-config", "static",
],
deps = [
"@crate_index//:anyhow",
"@crate_index//:bindgen",
"@crate_index//:lazy_static",
],
)

filegroup(
name = "g1",
output_group = "streams",
srcs = [ ":build_script" ],
)

filegroup(
name = "g2",
output_group = "out_dir",
srcs = [ ":build_script" ],
)

genrule(
name = "macros_rs",
srcs = [
":g2",
],
cmd = "cp $</macros.rs $@",
outs = [ "macros.rs", ],

)
Loading

0 comments on commit 304d979

Please sign in to comment.