|
1 | 1 | /*
|
2 |
| - * Copyright 2024 Oxide Computer Company |
| 2 | + * Copyright 2025 Oxide Computer Company |
3 | 3 | */
|
4 | 4 |
|
5 | 5 | mod common;
|
@@ -1828,9 +1828,11 @@ fn cmd_image(ca: &CommandArg) -> Result<()> {
|
1828 | 1828 | * Create the reset image for the Gimlet SPI ROM:
|
1829 | 1829 | */
|
1830 | 1830 | info!(log, "creating reset image...");
|
| 1831 | + let phbl_path = top_path(&["projects", "phbl"])?; |
| 1832 | + rustup_install_toolchain(log, &phbl_path)?; |
1831 | 1833 | ensure::run_in(
|
1832 | 1834 | log,
|
1833 |
| - &top_path(&["projects", "phbl"])?, |
| 1835 | + &phbl_path, |
1834 | 1836 | &[
|
1835 | 1837 | "cargo",
|
1836 | 1838 | "xtask",
|
@@ -2416,6 +2418,8 @@ fn cmd_setup(ca: &CommandArg) -> Result<()> {
|
2416 | 2418 | }
|
2417 | 2419 |
|
2418 | 2420 | let path = top_path(&["projects", &name])?;
|
| 2421 | + rustup_install_toolchain(log, &path)?; |
| 2422 | + |
2419 | 2423 | info!(log, "building project {:?} at {}", name, path.display());
|
2420 | 2424 | let start = Instant::now();
|
2421 | 2425 | let mut args = vec!["cargo", "build", "--locked"];
|
@@ -2618,6 +2622,37 @@ fn extract_hash(s: &str) -> Option<&str> {
|
2618 | 2622 | })
|
2619 | 2623 | }
|
2620 | 2624 |
|
| 2625 | +fn rustup_install_toolchain<P: AsRef<Path>>(log: &Logger, p: P) -> Result<()> { |
| 2626 | + let p = p.as_ref(); |
| 2627 | + |
| 2628 | + /* |
| 2629 | + * rustup 1.28.0 removed the long-standing default behavior of automatically |
| 2630 | + * installing toolchains for projects. It also introduces the ability to |
| 2631 | + * call "rustup toolchain install" with no argument to automatically install |
| 2632 | + * the current toolchain. Of course, this does not exist in earlier |
| 2633 | + * releases, and there was no transition period. |
| 2634 | + * |
| 2635 | + * "rustup show active-toolchain || rustup toolchain install" is the |
| 2636 | + * recommended way to just install the toolchain regardless of rustup |
| 2637 | + * version. |
| 2638 | + */ |
| 2639 | + info!(log, "checking rust toolchain is installed for {p:?}"); |
| 2640 | + let out = Command::new("rustup") |
| 2641 | + .args(["show", "active-toolchain"]) |
| 2642 | + .current_dir(p) |
| 2643 | + .output()?; |
| 2644 | + |
| 2645 | + if out.status.success() { |
| 2646 | + let ver = String::from_utf8_lossy(&out.stdout).trim().to_string(); |
| 2647 | + info!(log, "rust toolchain for {p:?}: {ver:?}"); |
| 2648 | + } else { |
| 2649 | + info!(log, "installing rust toolchain for {p:?}..."); |
| 2650 | + ensure::run_in(log, p, &["rustup", "toolchain", "install"])?; |
| 2651 | + } |
| 2652 | + |
| 2653 | + Ok(()) |
| 2654 | +} |
| 2655 | + |
2621 | 2656 | #[test]
|
2622 | 2657 | fn hash_extract() {
|
2623 | 2658 | assert_eq!(extract_hash("heads/trim-0-g49fb31d-dirty"), Some("49fb31d"));
|
|
0 commit comments