Skip to content

Commit 7ae203a

Browse files
committed
use system cargo in bazel, use concrete paths to search for files in bazel
1 parent 0630438 commit 7ae203a

5 files changed

Lines changed: 61 additions & 59 deletions

File tree

.github/actions/cpp-bazel/pre-merge/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ runs:
2929
- name: Setup Bazel with cache
3030
uses: ./.github/actions/utils/setup-cpp-with-cache
3131

32+
- name: Setup Rust with cache
33+
uses: ./.github/actions/utils/setup-rust-with-cache
34+
3235
- name: Install clang-format
3336
if: inputs.task == 'lint'
3437
shell: bash

foreign/cpp/BUILD.bazel

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ genrule(
2424
"Cargo.lock",
2525
"build.rs",
2626
],
27-
tools = [
28-
"@rules_rust//tools/upstream_wrapper:cargo",
29-
],
3027
outs = [
3128
"libiggy_cpp.a",
3229
"include/lib.rs.h",
@@ -35,7 +32,6 @@ genrule(
3532
cmd = """
3633
set -e
3734
38-
CARGO="$$(pwd)/$(execpath @rules_rust//tools/upstream_wrapper:cargo)"
3935
OUT_LIB="$$(pwd)/$(location libiggy_cpp.a)"
4036
OUT_RS="$$(pwd)/$(location include/lib.rs.h)"
4137
OUT_CXX="$$(pwd)/$(location cxxbridge/rust/cxx.h)"
@@ -50,11 +46,24 @@ genrule(
5046
FLAGS="--release"
5147
fi
5248
53-
env -u PWD CARGO_TARGET_DIR="target" "$$CARGO" build $$FLAGS --locked
49+
command -v cargo >/dev/null 2>&1 || { echo "cargo not found in PATH" >&2; exit 1; }
50+
env -u PWD CARGO_TARGET_DIR="target" cargo build $$FLAGS --locked
51+
52+
CARGO_TARGET_DIR="target"
53+
RUST_LIB="$$CARGO_TARGET_DIR/$$PROFILE/libiggy_cpp.a"
54+
RS_HEADER="$$CARGO_TARGET_DIR/cxxbridge/iggy-cpp/src/lib.rs.h"
55+
CXX_HEADER="$$CARGO_TARGET_DIR/cxxbridge/rust/cxx.h"
56+
57+
[ -f "$$RUST_LIB" ] || { echo "Rust static library not found at $$RUST_LIB" >&2; exit 1; }
58+
[ -f "$$RS_HEADER" ] || { echo "cxxbridge header file not found at $$RS_HEADER" >&2; exit 1; }
59+
if [ ! -f "$$CXX_HEADER" ] && [ ! -L "$$CXX_HEADER" ]; then
60+
echo "cxx.h not found at $$CXX_HEADER" >&2
61+
exit 1
62+
fi
5463
55-
cp "target/$$PROFILE/libiggy_cpp.a" "$$OUT_LIB"
56-
find "target/$$PROFILE/build" -name lib.rs.h | head -n 1 | xargs -I{} cp {} "$$OUT_RS"
57-
find "target/$$PROFILE/build" -name cxx.h | head -n 1 | xargs -I{} cp {} "$$OUT_CXX"
64+
cp "$$RUST_LIB" "$$OUT_LIB"
65+
cp "$$RS_HEADER" "$$OUT_RS"
66+
cp -L "$$CXX_HEADER" "$$OUT_CXX"
5867
""",
5968
local = 1,
6069
)

foreign/cpp/MODULE.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,5 @@ module(
2020
)
2121

2222
bazel_dep(name = "rules_cc", version = "0.2.16")
23-
bazel_dep(name = "rules_rust", version = "0.68.1")
2423
bazel_dep(name = "platforms", version = "1.0.0")
2524
bazel_dep(name = "googletest", version = "1.17.0")
26-
27-
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
28-
rust.toolchain(
29-
edition = "2024",
30-
versions = ["1.93.0"],
31-
)
32-
use_repo(rust, "rust_toolchains")

foreign/cpp/MODULE.bazel.lock

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

scripts/ci/sync-rust-version.sh

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ while [[ $# -gt 0 ]]; do
4141
--help|-h)
4242
echo "Usage: $0 [--check|--fix]"
4343
echo ""
44-
echo "Sync Rust version from rust-toolchain.toml to all Dockerfiles and Bazel MODULE files"
44+
echo "Sync Rust version from rust-toolchain.toml to all Dockerfiles"
4545
echo ""
4646
echo "Options:"
47-
echo " --check Check if all Dockerfiles and MODULE files have the correct Rust version"
48-
echo " --fix Update all Dockerfiles and MODULE files to use the correct Rust version"
47+
echo " --check Check if all Dockerfiles have the correct Rust version"
48+
echo " --fix Update all Dockerfiles to use the correct Rust version"
4949
echo " --help Show this help message"
5050
exit 0
5151
;;
@@ -84,7 +84,6 @@ echo ""
8484

8585
# Find all Dockerfiles
8686
DOCKERFILES=$(find . -name "Dockerfile*" -type f | grep -v node_modules | grep -v target | sort)
87-
MODULE_FILE="foreign/cpp/MODULE.bazel"
8887

8988
# Track misaligned files
9089
MISALIGNED_FILES=()
@@ -121,35 +120,12 @@ for dockerfile in $DOCKERFILES; do
121120
fi
122121
done
123122

124-
if [ -f "$MODULE_FILE" ] && grep -q 'versions = \["' "$MODULE_FILE" 2>/dev/null; then
125-
TOTAL_FILES=$((TOTAL_FILES + 1))
126-
127-
CURRENT_VERSION=$(grep 'versions = \["' "$MODULE_FILE" | head -1 | sed -E 's/.*versions = \["([^"]+)"\].*/\1/')
128-
129-
if [ "$MODE" = "check" ]; then
130-
if [ "$CURRENT_VERSION" != "$RUST_VERSION" ]; then
131-
MISALIGNED_FILES+=("$MODULE_FILE")
132-
echo -e "${RED}${NC} $MODULE_FILE: ${RED}$CURRENT_VERSION${NC} (expected: ${GREEN}$RUST_VERSION${NC})"
133-
else
134-
echo -e "${GREEN}${NC} $MODULE_FILE: $CURRENT_VERSION"
135-
fi
136-
elif [ "$MODE" = "fix" ]; then
137-
if [ "$CURRENT_VERSION" != "$RUST_VERSION" ]; then
138-
sed -i -E "s/(versions = \\[\")[^\"]+(\"\\])/\1$RUST_VERSION\2/" "$MODULE_FILE"
139-
FIXED_FILES=$((FIXED_FILES + 1))
140-
echo -e "${GREEN}Fixed${NC} $MODULE_FILE: ${RED}$CURRENT_VERSION${NC} -> ${GREEN}$RUST_VERSION${NC}"
141-
else
142-
echo -e "${GREEN}${NC} $MODULE_FILE: already correct ($RUST_VERSION)"
143-
fi
144-
fi
145-
fi
146-
147123
echo ""
148124
echo "────────────────────────────────────────────────"
149125

150126
if [ "$MODE" = "check" ]; then
151127
if [ ${#MISALIGNED_FILES[@]} -eq 0 ]; then
152-
echo -e "${GREEN}✓ All $TOTAL_FILES files are aligned with Rust versions (Dockerfiles: $RUST_VERSION_SHORT, MODULE files: $RUST_VERSION)${NC}"
128+
echo -e "${GREEN}✓ All $TOTAL_FILES files are aligned with Rust version (Dockerfiles: $RUST_VERSION_SHORT)${NC}"
153129
exit 0
154130
else
155131
echo -e "${RED}✗ Found ${#MISALIGNED_FILES[@]} misaligned file(s) out of $TOTAL_FILES:${NC}"
@@ -162,9 +138,9 @@ if [ "$MODE" = "check" ]; then
162138
fi
163139
elif [ "$MODE" = "fix" ]; then
164140
if [ $FIXED_FILES -eq 0 ]; then
165-
echo -e "${GREEN}✓ All $TOTAL_FILES files were already aligned with Rust versions (Dockerfiles: $RUST_VERSION_SHORT, MODULE files: $RUST_VERSION)${NC}"
141+
echo -e "${GREEN}✓ All $TOTAL_FILES files were already aligned with Rust version (Dockerfiles: $RUST_VERSION_SHORT)${NC}"
166142
else
167-
echo -e "${GREEN}✓ Fixed $FIXED_FILES out of $TOTAL_FILES files to use Rust versions (Dockerfiles: $RUST_VERSION_SHORT, MODULE files: $RUST_VERSION)${NC}"
143+
echo -e "${GREEN}✓ Fixed $FIXED_FILES out of $TOTAL_FILES files to use Rust version (Dockerfiles: $RUST_VERSION_SHORT)${NC}"
168144
fi
169145
exit 0
170146
fi

0 commit comments

Comments
 (0)