Skip to content

Commit 46e82ec

Browse files
committed
refactor(godbolt): rewrite wrapper as a stand-alone rust binary with integration test
1 parent a4743a8 commit 46e82ec

10 files changed

Lines changed: 817 additions & 254 deletions

File tree

contrib/godbolt/README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Rust GPU kernel code and see the resulting PTX assembly.
99
Compiler Explorer expects a single "compiler" binary that reads source on
1010
stdin or from a file and writes assembly to stdout. Since rust-cuda has no
1111
standalone compiler (the pipeline is `rustc` with a custom codegen backend
12-
plus `cargo` for dependency resolution), the integration uses a wrapper
13-
script that:
12+
plus `cargo` for dependency resolution), the integration uses a small Rust
13+
wrapper binary that:
1414

1515
1. Accepts a `.rs` file containing `#[kernel]` functions.
1616
2. Creates a temporary Cargo project that depends on `cuda_std`.
@@ -25,10 +25,10 @@ script that:
2525

2626
| File | Purpose |
2727
|------|---------|
28-
| `rust-cuda-wrapper.sh` | The wrapper script CE invokes as the "compiler" |
28+
| `rust-cuda-wrapper/` | Rust crate for the wrapper binary CE invokes as the "compiler" |
2929
| `rust-cuda.defaults.properties` | CE configuration (compiler type, flags, defaults) |
3030
| `rust-cuda.amazon.properties` | CE instance-specific overrides for the AWS fleet |
31-
| `install.sh` | Installs the pinned nightly, builds the codegen backend, and lays out the prefix |
31+
| `install.sh` | Installs the pinned nightly, builds the codegen backend and the wrapper, and lays out the prefix |
3232
| `test-kernel.rs` | Sample kernel with shared memory and thread indexing |
3333

3434
## Supported flags
@@ -61,7 +61,7 @@ export CUDA_PATH=/usr/local/cuda
6161
./contrib/godbolt/install.sh
6262

6363
# Then test:
64-
./contrib/godbolt/rust-cuda-wrapper.sh contrib/godbolt/test-kernel.rs
64+
$RUST_CUDA_ROOT/bin/rust-cuda-wrapper contrib/godbolt/test-kernel.rs
6565
```
6666

6767
You should see PTX assembly printed to stdout.
@@ -73,8 +73,21 @@ point the wrapper at the repo tree directly:
7373

7474
```bash
7575
export RUST_CUDA_ROOT=/path/to/rust-cuda
76-
# Ensure lib/librustc_codegen_nvvm.so exists at that path, or adjust
77-
# CODEGEN_SO in the script.
76+
# Ensure $RUST_CUDA_ROOT/lib/librustc_codegen_nvvm.so exists.
77+
78+
cd contrib/godbolt/rust-cuda-wrapper
79+
cargo run --release -- ../test-kernel.rs
80+
```
81+
82+
### Running the integration test
83+
84+
The wrapper crate ships a smoke test that compiles `test-kernel.rs`
85+
end-to-end and asserts the output looks like PTX:
86+
87+
```bash
88+
cd contrib/godbolt/rust-cuda-wrapper
89+
cargo test # skips without RUST_CUDA_ROOT
90+
RUST_CUDA_ROOT=/path/to/rust-cuda cargo test # runs the real build
7891
```
7992

8093
## Submitting to Compiler Explorer

contrib/godbolt/install.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,14 @@ done
104104
# important so dependency resolution is reproducible).
105105
cp "${REPO_DIR}/Cargo.lock" "${INSTALL_PREFIX}/" 2>/dev/null || true
106106

107-
# The wrapper script.
108-
cp "${REPO_DIR}/contrib/godbolt/rust-cuda-wrapper.sh" "${INSTALL_PREFIX}/bin/"
109-
chmod +x "${INSTALL_PREFIX}/bin/rust-cuda-wrapper.sh"
107+
# Build and install the wrapper binary.
108+
(
109+
cd "${REPO_DIR}/contrib/godbolt/rust-cuda-wrapper"
110+
cargo build --release
111+
)
112+
cp "${REPO_DIR}/contrib/godbolt/rust-cuda-wrapper/target/release/rust-cuda-wrapper" \
113+
"${INSTALL_PREFIX}/bin/"
114+
chmod +x "${INSTALL_PREFIX}/bin/rust-cuda-wrapper"
110115

111116
# Version marker.
112117
echo "${NIGHTLY}" > "${INSTALL_PREFIX}/rust-toolchain-version"
@@ -121,4 +126,4 @@ echo "==> Installation complete."
121126
echo ""
122127
echo "Test with:"
123128
echo " RUST_CUDA_ROOT=${INSTALL_PREFIX} CUDA_PATH=${CUDA_PATH} \\"
124-
echo " ${INSTALL_PREFIX}/bin/rust-cuda-wrapper.sh contrib/godbolt/test-kernel.rs"
129+
echo " ${INSTALL_PREFIX}/bin/rust-cuda-wrapper contrib/godbolt/test-kernel.rs"

contrib/godbolt/rust-cuda-wrapper.sh

Lines changed: 0 additions & 241 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)