Repository navigation
rerun cpp-overload-test build script when src/ changes #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| fn main() { | ||
| // `cc` prints `rerun-if-env-changed` lines, which turns off Cargo's default rescan of the | ||
| // package, so instruct Cargo to rerun this script whenever `src/` changes and pick up | ||
| // `cpp!` updates. | ||
| println!("cargo::rerun-if-changed=src"); | ||
|
teor2345 marked this conversation as resolved.
Resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be great to upstream this fix to If you do have time to do both, feel free to include it in your Outreachy application.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hi teor, i have created a pr upstream suggesting a fix for the build script, mystor/rust-cpp#118.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, I see that it has been merged, congratulations! |
||
| // `cpp_build` doesn't work with multiple example/binary builds in the same crate, so we use | ||
| // lib.rs submodules for successful overloads. | ||
| cpp_build::Config::new() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
| # Checks that new or changed `cpp!` blocks get compiled after an edit, without running | ||
| # `cargo clean` or touching `build.rs`. See `src/rerun_check.rs` for details. | ||
| set -euo pipefail | ||
|
|
||
| cd "$(dirname "$0")" | ||
| ORIGINAL=src/rerun_check.rs | ||
| REPLACEMENT=rerun-check/rerun_check.rs | ||
| BACKUP=$(mktemp) | ||
| cp "$ORIGINAL" "$BACKUP" | ||
| trap 'cp "$BACKUP" "$ORIGINAL"; rm -f "$BACKUP"' EXIT | ||
|
|
||
| run_check() { | ||
| local output | ||
| if ! output=$(cargo test --all-features --package cpp-overload-test --lib rerun_check 2>&1); then | ||
| echo "$output" | ||
| return 1 | ||
| fi | ||
| echo "$output" | ||
| # A test filter that matches nothing still passes, so check that the test actually ran. | ||
| if ! grep -q "test rerun_check::test_rerun_check ... ok" <<<"$output"; then | ||
| echo "rerun_check::test_rerun_check didn't run" >&2 | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| echo "Testing the original cpp! code:" | ||
| run_check | ||
|
|
||
| # Make sure the replacement is newer than the last build, even with coarse file timestamps. | ||
| sleep 1 | ||
| echo "Replacing the cpp! code, then testing again without cargo clean:" | ||
| cp "$REPLACEMENT" "$ORIGINAL" | ||
| run_check | ||
| echo "cpp! changes were rebuilt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //! The replacement for `src/rerun_check.rs` that `rerun-check.sh` swaps in. | ||
| //! | ||
| //! It changes the C++ code in the existing `cpp!` block and adds a new `cpp!` block, so the | ||
| //! second test run covers both kinds of change. | ||
|
|
||
| use cpp::cpp; | ||
|
|
||
| /// A value from an existing `cpp!` block, which this file changes. | ||
| fn changed_value() -> i32 { | ||
| unsafe { cpp!([] -> i32 as "int" { return 2; }) } | ||
| } | ||
|
|
||
| /// A value from a new `cpp!` block. | ||
| fn added_value() -> i32 { | ||
| unsafe { cpp!([] -> i32 as "int" { return 3; }) } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_rerun_check() { | ||
| assert_eq!(changed_value(), 2); | ||
| assert_eq!(added_value(), 3); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //! Checks that new or changed `cpp!` blocks get compiled without needing `cargo clean`. | ||
| //! | ||
| //! `rerun-check.sh` runs the tests in this file, then swaps it for `rerun-check/rerun_check.rs`, | ||
| //! and runs the tests again. The second run only passes if `build.rs` reruns `cpp_build` | ||
| //! when a file under `src/` changes. | ||
|
|
||
| use cpp::cpp; | ||
|
|
||
| /// A value from an existing `cpp` block, which the replacement file changes. | ||
| fn changed_value() -> i32 { | ||
| unsafe { cpp!([] -> i32 as "int" { return 1; }) } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_rerun_check() { | ||
| assert_eq!(changed_value(), 1); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally I would split this out into a separate job, but we're getting a lot of jobs now, so I don't think it matters that much.
If it turns out this job is always the slowest, or it fails, we can change it later.