Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 63 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,31 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive

- name: Install yq
run: |
set -euo pipefail
YQ_VERSION="v4.52.4"
mkdir -p "$HOME/.local/bin"
wget -qO "$HOME/.local/bin/yq" \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
chmod +x "$HOME/.local/bin/yq"
Comment thread
cds-amal marked this conversation as resolved.
Outdated
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: 'Read nightly channel from rust-toolchain.toml'
id: toolchain-meta
run: |
set -euo pipefail
CHANNEL=$(yq -r '.toolchain.channel' rust-toolchain.toml)
if [ -z "$CHANNEL" ] || [ "$CHANNEL" = "null" ]; then
echo "::error::Could not read toolchain.channel from rust-toolchain.toml"
exit 1
fi
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"

- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-11-29 # Hardcoded version, same as is in the build.rs
toolchain: ${{ steps.toolchain-meta.outputs.channel }}

- name: 'Build stable-mir-json' # rustfmt documentation claims it is unstable on code that doesn't build
run: |
Expand Down Expand Up @@ -66,10 +87,31 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
submodules: recursive

- name: Install yq
run: |
set -euo pipefail
YQ_VERSION="v4.52.4"
mkdir -p "$HOME/.local/bin"
wget -qO "$HOME/.local/bin/yq" \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
chmod +x "$HOME/.local/bin/yq"
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: 'Read nightly channel from rust-toolchain.toml'
id: toolchain-meta
run: |
set -euo pipefail
CHANNEL=$(yq -r '.toolchain.channel' rust-toolchain.toml)
if [ -z "$CHANNEL" ] || [ "$CHANNEL" = "null" ]; then
echo "::error::Could not read toolchain.channel from rust-toolchain.toml"
exit 1
fi
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"

- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-11-29 # Hardcoded version, same as is in the build.rs
toolchain: ${{ steps.toolchain-meta.outputs.channel }}

- name: 'Build stable-mir-json'
run: | # Warning check should be redundant since code-quality runs first
Expand Down Expand Up @@ -108,16 +150,30 @@ jobs:
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
chmod +x "$HOME/.local/bin/yq"
echo "$HOME/.local/bin" >> $GITHUB_PATH
yq --version

- name: 'Read nightly channel from rust-toolchain.toml'
id: toolchain-meta
run: |
set -euo pipefail
CHANNEL=$(yq -r '.toolchain.channel' rust-toolchain.toml)
if [ -z "$CHANNEL" ] || [ "$CHANNEL" = "null" ]; then
echo "::error::Could not read toolchain.channel from rust-toolchain.toml"
exit 1
fi
echo "channel=$CHANNEL" >> "$GITHUB_OUTPUT"

- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.toolchain-meta.outputs.channel }}

- name: 'Read rustc commit from rust-toolchain.toml'
- name: 'Derive rustc commit and check out Rust repo'
id: rustc-meta
run: |
set -euo pipefail
COMMIT=$(yq '.metadata.rustc-commit' rust-toolchain.toml)
if [ -z "$COMMIT" ] || [ "$COMMIT" = "null" ]; then
echo "::error::metadata.rustc-commit not found in rust-toolchain.toml"
COMMIT=$(rustc -vV | grep 'commit-hash' | cut -d' ' -f2)
if [ -z "$COMMIT" ]; then
echo "::error::Could not determine rustc commit-hash from 'rustc -vV'"
exit 1
fi
echo "rustc-commit=$COMMIT" >> "$GITHUB_OUTPUT"
Expand All @@ -130,11 +186,6 @@ jobs:
path: rust
fetch-depth: 1

- name: "Set up nightly Rust" # https://github.com/rust-lang/rustup/issues/3409
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-11-29 # Hardcoded version, same as is in the build.rs

- name: 'Build stable-mir-json'
run: | # Warning check should be redundant since code-quality runs first
RUSTFLAGS='--deny warnings' cargo build -vv
Expand Down
180 changes: 162 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,66 @@
RELEASE_FLAG=
TOOLCHAIN_NAME=''
TOOLCHAIN_NAME=

default: build
.DEFAULT_GOAL := build

.PHONY: help
## Show this help message
help:
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} \
/^###/ {printf "\n\033[1m%s\033[0m\n", substr($$0, 5); next} \
/^##/ {description=substr($$0, 4)} \
/^[a-zA-Z0-9_-]+:/ { \
if (description) { \
printf " \033[36m%-18s\033[0m %s\n", $$1, description; \
description = ""; \
} \
}' $(MAKEFILE_LIST)

### Build

.PHONY: build
## Build the project (use RELEASE_FLAG=--release for release)
build:
cargo build ${RELEASE_FLAG}
cargo build $(RELEASE_FLAG)

.PHONY: clean
## Clean build artifacts, toolchain overrides, and graphs
clean: rustup-clear-toolchain clean-graphs
cargo clean

.PHONY: rustup-clear-toolchain
rustup-clear-toolchain:
rustup override unset
rustup override unset --nonexistent
rustup toolchain uninstall "${TOOLCHAIN_NAME}"
rustup toolchain uninstall "$(TOOLCHAIN_NAME)"
Comment thread
cds-amal marked this conversation as resolved.
Outdated

### Test

TESTDIR=tests/integration/programs

# Detect the active nightly for golden-file lookup.
# The nightly name (e.g. nightly-2025-03-01) is derived from rustc's
# commit-date, which is one day before the nightly date. We add one day
# to align with the toolchain channel name that users actually see.
NIGHTLY_COMMIT_DATE := $(shell rustc -vV 2>/dev/null | awk '/^commit-date:/{print $$2}')
# Portable +1 day: macOS date(1) uses -v+1d, GNU date uses -d "+1 day".
NIGHTLY_DATE := $(shell \
if [ -n "$(NIGHTLY_COMMIT_DATE)" ]; then \
date -j -v+1d -f "%Y-%m-%d" "$(NIGHTLY_COMMIT_DATE)" "+%Y-%m-%d" 2>/dev/null \
|| date -d "$(NIGHTLY_COMMIT_DATE) +1 day" "+%Y-%m-%d" 2>/dev/null \
|| echo "$(NIGHTLY_COMMIT_DATE)"; \
fi)
ACTIVE_NIGHTLY := nightly-$(NIGHTLY_DATE)

.PHONY: integration-test
integration-test: TESTS ?= $(shell find $(TESTDIR) -type f -name "*.rs")
integration-test: SMIR ?= cargo run -- "-Zno-codegen"
# override this to tweak how expectations are formatted
integration-test: NORMALIZE ?= jq -S -e -f $(TESTDIR)/../normalise-filter.jq
# override this to re-make golden files
integration-test: DIFF ?= | diff -
## Run integration tests against expected outputs
integration-test:
errors=""; \
report() { echo "$$1: $$2"; errors="$$errors\n$$1: $$2"; }; \
Expand All @@ -39,19 +76,12 @@ integration-test:
done; \
[ -z "$$errors" ] || (echo "===============\nFAILING TESTS:$$errors"; exit 1)


.PHONY: golden
golden:
make integration-test DIFF=">"

format:
cargo fmt
bash -O globstar -c 'nixfmt **/*.nix'

style-check: format
cargo clippy -- -Dwarnings

.PHONY: remake-ui-tests test-ui

.PHONY: remake-ui-tests
## Regenerate UI test fixtures (requires RUST_DIR_ROOT)
remake-ui-tests:
# Check if RUST_DIR_ROOT is set
if [ -z "$$RUST_DIR_ROOT" ]; then \
Expand All @@ -61,20 +91,77 @@ remake-ui-tests:
# This will run without saving source files. Run the script manually to do this.
bash tests/ui/remake_ui_tests.sh "$$RUST_DIR_ROOT"

.PHONY: test-ui
## Run UI tests (requires RUST_DIR_ROOT, VERBOSE=1 for details)
test-ui: VERBOSE?=0
test-ui:
bash tests/ui/run_ui_tests.sh $(if $(filter 1,$(VERBOSE)),--verbose) "$$RUST_DIR_ROOT"

.PHONY: dot svg png d2 clean-graphs check-graphviz
.PHONY: test-directives
## Run unit tests for the directive parser (parse_test_directives.awk)
test-directives:
bash tests/ui/test_directives_test.sh

.PHONY: test-ui-emit
## Generate effective UI test lists for a nightly (requires RUST_DIR_ROOT, NIGHTLY=nightly-YYYY-MM-DD)
test-ui-emit:
bash tests/ui/diff_test_lists.sh --emit "$$RUST_DIR_ROOT" $(NIGHTLY)

### Nightly management

.PHONY: nightly-add
## Add support for a new nightly (requires NIGHTLY, RUST_DIR_ROOT)
nightly-add:
@test -n "$$NIGHTLY" || { echo "Error: NIGHTLY not set (e.g., NIGHTLY=nightly-2025-08-01)"; exit 1; }
@test -n "$$RUST_DIR_ROOT" || { echo "Error: RUST_DIR_ROOT not set"; exit 1; }
python3 scripts/nightly_admin.py add "$$NIGHTLY" --rust-dir "$$RUST_DIR_ROOT"

.PHONY: nightly-check
## Run all tests for a nightly (requires NIGHTLY, RUST_DIR_ROOT)
nightly-check:
@test -n "$$NIGHTLY" || { echo "Error: NIGHTLY not set"; exit 1; }
@test -n "$$RUST_DIR_ROOT" || { echo "Error: RUST_DIR_ROOT not set"; exit 1; }
python3 scripts/nightly_admin.py check "$$NIGHTLY" --rust-dir "$$RUST_DIR_ROOT"

.PHONY: nightly-bump
## Bump the pinned nightly (requires NIGHTLY)
nightly-bump:
@test -n "$$NIGHTLY" || { echo "Error: NIGHTLY not set"; exit 1; }
python3 scripts/nightly_admin.py bump "$$NIGHTLY"

### Diagnostics

.PHONY: build-info
## Show build.rs cfg detection output (rustc commit-date, enabled flags)
build-info:
@touch build.rs
@cargo build -vv 2>&1 | grep '\] build\.rs:'

### Code quality

.PHONY: fmt format
## Format Rust and Nix source files
fmt format:
cargo fmt
bash -O globstar -c 'nixfmt **/*.nix'

.PHONY: clippy
## Run clippy lint checks (deny warnings)
clippy:
cargo clippy -- -Dwarnings

.PHONY: style-check
## Run format + clippy lint checks
style-check: format clippy

### Graph generation

OUTDIR_DOT=output-dot
OUTDIR_SVG=output-svg
OUTDIR_PNG=output-png
OUTDIR_D2=output-d2

clean-graphs:
@rm -rf $(OUTDIR_DOT) $(OUTDIR_SVG) $(OUTDIR_PNG) $(OUTDIR_D2)

.PHONY: check-graphviz
check-graphviz:
@command -v dot >/dev/null 2>&1 || { \
echo "Error: Graphviz is not installed or 'dot' is not in PATH."; \
Expand All @@ -83,6 +170,8 @@ check-graphviz:
exit 1; \
}

.PHONY: dot
## Generate DOT files from test programs
dot:
@mkdir -p $(OUTDIR_DOT)
@for rs in $(TESTDIR)/*.rs; do \
Expand All @@ -92,6 +181,8 @@ dot:
mv $$name.smir.dot $(OUTDIR_DOT)/ 2>/dev/null || true; \
done

.PHONY: svg
## Generate SVG files from DOT (requires graphviz)
svg: check-graphviz dot
@mkdir -p $(OUTDIR_SVG)
@for dotfile in $(OUTDIR_DOT)/*.dot; do \
Expand All @@ -100,6 +191,8 @@ svg: check-graphviz dot
dot -Tsvg $$dotfile -o $(OUTDIR_SVG)/$$name.svg; \
done

.PHONY: png
## Generate PNG files from DOT (requires graphviz)
png: check-graphviz dot
@mkdir -p $(OUTDIR_PNG)
@for dotfile in $(OUTDIR_DOT)/*.dot; do \
Expand All @@ -108,6 +201,8 @@ png: check-graphviz dot
dot -Tpng $$dotfile -o $(OUTDIR_PNG)/$$name.png; \
done

.PHONY: d2
## Generate D2 diagram files from test programs
d2:
@mkdir -p $(OUTDIR_D2)
@for rs in $(TESTDIR)/*.rs; do \
Expand All @@ -116,3 +211,52 @@ d2:
cargo run --release -- --d2 -Zno-codegen $$rs 2>/dev/null; \
mv $$name.smir.d2 $(OUTDIR_D2)/ 2>/dev/null || true; \
done

.PHONY: clean-graphs
## Remove generated graph output directories
clean-graphs:
@rm -rf $(OUTDIR_DOT) $(OUTDIR_SVG) $(OUTDIR_PNG) $(OUTDIR_D2)

### stdlib smir.json

STDLIB_OUTDIR=tests/stdlib-artifacts
STDLIB_TARGET=$(shell rustc --print target-triple 2>/dev/null || rustc -vV | grep host | awk '{print $$2}')
SYSROOT=$(shell rustc --print sysroot)
SMIR_BIN=$(CURDIR)/target/debug/stable_mir_json

.PHONY: stdlib-smir
## Generate smir.json for stdlib via -Zbuild-std
stdlib-smir: build
@# Create a throwaway crate to drive -Zbuild-std
$(eval STDLIB_TMPDIR := $(shell mktemp -d))
@echo '[package]' > $(STDLIB_TMPDIR)/Cargo.toml
@echo 'name = "stdlib-smir"' >> $(STDLIB_TMPDIR)/Cargo.toml
@echo 'version = "0.0.0"' >> $(STDLIB_TMPDIR)/Cargo.toml
@echo 'edition = "2021"' >> $(STDLIB_TMPDIR)/Cargo.toml
@echo '[[bin]]' >> $(STDLIB_TMPDIR)/Cargo.toml
@echo 'name = "stdlib-smir"' >> $(STDLIB_TMPDIR)/Cargo.toml
@echo 'path = "main.rs"' >> $(STDLIB_TMPDIR)/Cargo.toml
@echo 'fn main() {}' > $(STDLIB_TMPDIR)/main.rs
@# Build stdlib through our driver; set library path the same way
@# cargo does when it runs our binary via `cargo run`
cd $(STDLIB_TMPDIR) && \
DYLD_LIBRARY_PATH=$(SYSROOT)/lib \
LD_LIBRARY_PATH=$(SYSROOT)/lib \
RUSTC=$(SMIR_BIN) \
cargo build -Zbuild-std --target $(STDLIB_TARGET)
@# Collect artifacts, stripping hash suffixes from filenames
@rm -rf $(STDLIB_OUTDIR)
@mkdir -p $(STDLIB_OUTDIR)
@for f in $(STDLIB_TMPDIR)/target/$(STDLIB_TARGET)/debug/deps/*.smir.json; do \
name=$$(basename "$$f" | sed 's/-[0-9a-f]*\.smir\.json/.smir.json/'); \
case "$$name" in stdlib_smir*) continue ;; esac; \
cp "$$f" $(STDLIB_OUTDIR)/$$name; \
done
@rm -rf $(STDLIB_TMPDIR)
@echo "stdlib smir.json artifacts written to $(STDLIB_OUTDIR)/"
@ls -lhS $(STDLIB_OUTDIR)/

.PHONY: clean-stdlib-smir
## Remove stdlib smir.json artifacts
clean-stdlib-smir:
@rm -rf $(STDLIB_OUTDIR)
6 changes: 0 additions & 6 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[toolchain]
channel = "nightly-2024-11-29"
components = ["llvm-tools", "rustc-dev", "rust-src", "rust-analyzer"]
Comment thread
cds-amal marked this conversation as resolved.

# Ignored by rustup; used by our test scripts.
# This is the rustc commit that backs the nightly above.
# UI test scripts automatically checkout this commit in RUST_DIR_ROOT.
[metadata]
rustc-commit = "a2545fd6fc66b4323f555223a860c451885d1d2b"
Loading
Loading