Skip to content

Commit 401ee4a

Browse files
committed
feat: adds a partial setup to build rust_icu_sys with bazel
This is an experimental change, hopefully will include other crates too.
1 parent cfbd691 commit 401ee4a

File tree

10 files changed

+3601
-68
lines changed

10 files changed

+3601
-68
lines changed

Cargo.Bazel.lock

Lines changed: 3395 additions & 0 deletions
Large diffs are not rendered by default.

MODULE.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ go_deps.from_file(go_mod = "//:go.mod")
2121
use_repo(go_deps)
2222

2323
bazel_dep(name = "rules_foreign_cc", version = "0.10.1")
24-
2524
bazel_dep(name = "toolchains_llvm", version = "1.0.0")
2625

2726
# Configure and register the toolchain.
@@ -31,7 +30,6 @@ llvm.toolchain(
3130
# work with just any version of LLVM.
3231
llvm_version = "15.0.6",
3332
)
34-
3533
use_repo(llvm, "llvm_toolchain")
3634

3735
register_toolchains("@llvm_toolchain//:all")

MODULE.bazel.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE

Lines changed: 102 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,132 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3+
4+
http_archive(
5+
name = "rules_rust",
6+
sha256 = "36ab8f9facae745c9c9c1b33d225623d976e78f2cc3f729b7973d8c20934ab95",
7+
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.31.0/rules_rust-v0.31.0.tar.gz"],
8+
)
9+
10+
load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains")
11+
12+
rules_rust_dependencies()
13+
14+
rust_register_toolchains(
15+
edition = "2021",
16+
versions = ["1.79.0"],
17+
)
18+
19+
######################################################################
20+
21+
# Use to generate rust-project.json.
22+
# Use bazel run @rules_rust//tools/rust_analyzer:gen_rust_project
23+
24+
load(
25+
"@rules_rust//tools/rust_analyzer:deps.bzl",
26+
"rust_analyzer_dependencies",
27+
)
28+
29+
rust_analyzer_dependencies()
30+
31+
######################################################################
32+
33+
# This is how to generate new lock files. At the project outset, you must
34+
# (1) create the empty files `//third_party/cargo:Cargo.lock`, and
35+
# `//third_party/cargo:Cargo.Bazel.lock`.
36+
# (2) Run `env CARGO_BAZEL_REPI=true bazel build //...` to initialize the
37+
# lockfiles.
38+
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository", "render_config")
39+
40+
crates_repository(
41+
name = "crate_index",
42+
cargo_lockfile = "//:Cargo.lock",
43+
lockfile = "//:Cargo.Bazel.lock",
44+
packages = {
45+
# Add any other crates you need here.
46+
"bumpalo": crate.spec(
47+
version = "3.6.1",
48+
),
49+
"libc": crate.spec(
50+
version = "0.2.34",
51+
),
52+
"paste": crate.spec(
53+
version = "1.0",
54+
),
55+
"anyhow": crate.spec(
56+
version = "1.0.72",
57+
),
58+
"bindgen": crate.spec(
59+
version = "0.59.2",
60+
),
61+
"lazy_static": crate.spec(
62+
version = "1.4.0",
63+
),
64+
},
65+
render_config = render_config(
66+
default_package_name = "",
67+
),
68+
)
69+
70+
load("@crate_index//:defs.bzl", "crate_repositories")
71+
72+
crate_repositories()
73+
74+
######################################################################
275

376
http_archive(
477
name = "icu_74",
5-
strip_prefix = "icu-release-74-2",
6-
integrity = "sha256-J7hlCpTfb5Rcs7aGvjvjIMKjLt8+zimBZyv5i7O6qeE=",
778
build_file = "//third_party/icu_74:icu.BUILD.bazel",
8-
urls = [
9-
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.tar.gz",
10-
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.zip",
79+
integrity = "sha256-J7hlCpTfb5Rcs7aGvjvjIMKjLt8+zimBZyv5i7O6qeE=",
80+
patch_args = [
81+
"-p1",
82+
# Without this flag, the bazel build files just get emptied, but not
83+
# removed. This is not enough.
84+
"--remove-empty-files",
1185
],
1286
patches = [
1387
# ICU has a nascent bazel build, which messes up our build based on
1488
# the configure_make rule from rules_foreign_cc. So we remove them.
1589
"//third_party/icu_74:0001-fix-removes-BUILD-files.patch",
1690
],
17-
patch_args = [
18-
"-p1",
19-
# Without this flag, the bazel build files just get emptied, but not
20-
# removed. This is not enough.
21-
"--remove-empty-files",
22-
]
91+
strip_prefix = "icu-release-74-2",
92+
urls = [
93+
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.tar.gz",
94+
"https://github.com/unicode-org/icu/archive/refs/tags/release-74-2.zip",
95+
],
2396
)
2497

2598
http_archive(
2699
name = "icu_73",
27-
strip_prefix = "icu-release-73-1",
28-
integrity = "sha256-57a1QMiB6D0kC0oSty+8l+9frTDY0A8u9nS6GOO/NkA=",
29100
build_file = "//third_party/icu_73:icu.BUILD.bazel",
30-
urls = [
31-
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.tar.gz",
32-
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.zip",
101+
integrity = "sha256-57a1QMiB6D0kC0oSty+8l+9frTDY0A8u9nS6GOO/NkA=",
102+
patch_args = [
103+
"-p1",
104+
"--remove-empty-files",
33105
],
34106
patches = [
35107
"//third_party/icu_73:0001-fix-removes-BUILD-files.patch",
36108
],
37-
patch_args = [
38-
"-p1",
39-
"--remove-empty-files",
40-
]
109+
strip_prefix = "icu-release-73-1",
110+
urls = [
111+
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.tar.gz",
112+
"https://github.com/unicode-org/icu/archive/refs/tags/release-73-1.zip",
113+
],
41114
)
42115

43116
http_archive(
44117
name = "icu_72",
45-
strip_prefix = "icu-release-72-1",
46-
integrity = "sha256-Q8utYo2Y83o/lfbDRXn5FE70veYCSPpgBKTwBtdIfmk=",
47118
build_file = "//third_party/icu_72:icu.BUILD.bazel",
48-
urls = [
49-
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.tar.gz",
50-
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.zip",
119+
integrity = "sha256-Q8utYo2Y83o/lfbDRXn5FE70veYCSPpgBKTwBtdIfmk=",
120+
patch_args = [
121+
"-p1",
122+
"--remove-empty-files",
51123
],
52124
patches = [
53125
"//third_party/icu_72:0001-fix-removes-BUILD-files.patch",
54126
],
55-
patch_args = [
56-
"-p1",
57-
"--remove-empty-files",
58-
]
127+
strip_prefix = "icu-release-72-1",
128+
urls = [
129+
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.tar.gz",
130+
"https://github.com/unicode-org/icu/archive/refs/tags/release-72-1.zip",
131+
],
59132
)

rust_icu_sys/BUILD.bazel

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
2+
load("@rules_rust//rust:defs.bzl", "rust_library")
3+
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
4+
5+
package(default_visibility = ["//visibility:public"])
6+
7+
rust_library(
8+
name = "rust_icu_sys",
9+
srcs = [
10+
"src/lib.rs",
11+
"tests/hygiene.rs",
12+
":macros_rs",
13+
],
14+
crate_name = "rust_icu_sys",
15+
edition = "2021",
16+
proc_macro_deps = [
17+
"@crate_index//:paste",
18+
],
19+
deps = [
20+
"@crate_index//:libc",
21+
":build_script",
22+
"@icu_74//:icu",
23+
],
24+
)
25+
26+
cargo_build_script(
27+
name = "build_script",
28+
srcs = [ "build.rs" ],
29+
crate_features = [
30+
"use-bindgen", "bindgen", "renaming", "icu-config", "static",
31+
],
32+
deps = [
33+
"@crate_index//:anyhow",
34+
"@crate_index//:bindgen",
35+
"@crate_index//:lazy_static",
36+
],
37+
)
38+
39+
filegroup(
40+
name = "g1",
41+
output_group = "streams",
42+
srcs = [ ":build_script" ],
43+
)
44+
45+
filegroup(
46+
name = "g2",
47+
output_group = "out_dir",
48+
srcs = [ ":build_script" ],
49+
)
50+
51+
genrule(
52+
name = "macros_rs",
53+
srcs = [
54+
":g2",
55+
],
56+
cmd = "cp $</macros.rs $@",
57+
outs = [ "macros.rs", ],
58+
59+
)

0 commit comments

Comments
 (0)