-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUILD.bazel
More file actions
134 lines (125 loc) · 4.81 KB
/
Copy pathBUILD.bazel
File metadata and controls
134 lines (125 loc) · 4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_test")
package(default_visibility = ["//visibility:public"])
# =============================================================================
# Library
# =============================================================================
# All 33 top-level modules + their nested sub-directories are captured by the
# recursive glob. Path aliases like `#[path = "2d/mod.rs"]` in src/lib.rs and
# sub-module `mod.rs` files are transparent to Bazel — rustc resolves them at
# compile time. `.bak` files are excluded as build pollution.
#
# `src/tests/**` is excluded here because the files under it are not part of
# the cocos4-rust library (lib.rs has no `mod tests;` declaration). They
# would only be valid as either (a) a separate integration test crate —
# rejected because their `use crate::math::...` / `use crate::storage::...`
# imports assume they're INSIDE cocos4-rust — or (b) an external binary
# (quaternion_test.rs) which we handle separately as //:quaternion_demo.
LIB_SRCS = glob(
[
"src/**/*.rs",
],
exclude = [
"src/main.rs",
"src/tests/**",
"**/*.bak",
],
)
rust_library(
name = "cocos4_rust",
srcs = LIB_SRCS,
crate_root = "src/lib.rs",
edition = "2021",
crate_features = [
# Matches Cargo.toml `default` features. `js-runtime-real` is
# intentionally NOT enabled by default in the Bazel build. We
# verified the wiring (boa_engine/serde_json materialize into
# @crates//:) by flipping the feature on once — see the comment
# below for the cargo-bazel path-member workaround and the
# downstream toolchain blocker (regress 0.10.x requires nightly).
# Re-enable by:
# 1. Add "js-runtime-real" to crate_features below.
# 2. Add "@crates//:boa_engine", "@crates//:serde_json" to deps.
# 3. Make boa_engine/serde_json NON-optional direct deps in
# Cargo.toml (cargo-bazel 0.61.0 ignores
# `crate.annotation(crate_features = [...])` for path
# members; declaring them as required direct deps is the
# bypass).
# 4. Add a stable-capable regress pin in Cargo.lock (regress
# 0.10.1+ uses `if`/`let` chains — rust-lang/rust#53667,
# #54725 — which are nightly-only). Easiest path: pin
# regress 0.10.0 in Cargo.toml's [patch.crates-io] with a
# path source mirroring the vendor/paste/ trick; or
# upgrade the Bazel rust toolchain to nightly.
"std",
"gfx-empty",
"gfx-validator",
"gfx-wgpu",
"gfx-agent",
"pipeline-custom",
"pipeline-deferred",
"physics-2d",
"network-real",
"platform-real",
"storage-disk",
"dragon-bones",
"spine",
"js-bindings",
"terrain",
"tiled-map",
],
deps = [
# External crates — names match crate_universe's `@crates//:` namespace,
# which is generated from Cargo.lock.
"@crates//:bitflags",
"@crates//:lazy_static",
"@crates//:rand",
],
)
# =============================================================================
# Binary
# =============================================================================
rust_binary(
name = "cocos4-rust",
srcs = ["src/main.rs"],
crate_root = "src/main.rs",
edition = "2021",
deps = [":cocos4_rust"],
)
# =============================================================================
# Tests
# =============================================================================
# All 1837 inline `#[cfg(test)] mod tests { ... }` blocks across 240 .rs files
# are exercised by re-compiling the library in test mode. rules_rust's
# `rust_test` with `crate = ":lib"` wires the lib sources back in automatically.
rust_test(
name = "cocos4_rust_test",
crate = ":cocos4_rust",
# No `srcs` — crate = :cocos4_rust supplies the test compilation unit
)
# Orphan: src/tests/quaternion_test.rs is a stand-alone binary (fn main()).
# Preserved per project decision — exposed as :quaternion_demo. The
# `use cocos4_rust::math::...` import assumes the binary links against
# `//:cocos4_rust` (declared in `deps`).
rust_binary(
name = "quaternion_demo",
srcs = ["src/tests/quaternion_test.rs"],
crate_root = "src/tests/quaternion_test.rs",
edition = "2021",
deps = [":cocos4_rust"],
)
# Aggregate suite so `bazel test //...` and `bazel test //:all_tests` both
# return a single PASS/FAIL summary.
test_suite(
name = "all_tests",
tests = [
":cocos4_rust_test",
],
)
# Aggregate build target for convenience
filegroup(
name = "all_sources",
srcs = glob(["src/**/*.rs", "src/**/*.bak"]) + [
"Cargo.toml",
"Cargo.lock",
],
)