Skip to content

Commit

Permalink
Merge pull request #1597 from axodotdev/disable_axoupdater_source
Browse files Browse the repository at this point in the history
feat: disable axoupdater-from-source
  • Loading branch information
mistydemeo authored Dec 10, 2024
2 parents 47358d2 + 79e23bb commit dccb10a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 75 deletions.
22 changes: 10 additions & 12 deletions cargo-dist/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ pub enum DistError {
tool: String,
},

/// Unknown target requested
#[error(
"A build was requested for {target}, but the standalone updater isn't available for it."
)]
#[diagnostic(help("At the moment, we can only provide updater binaries for the core set of most common target triples. Please set `install-updater = false` in your config."))]
NoAxoupdaterForTarget {
/// The target triple being built for
target: String,
},

/// reqwest returned non-2xx/404 when checking axoupdater releases
#[error("Failed to check the latest release of axoupdater")]
#[diagnostic(help(
Expand Down Expand Up @@ -595,18 +605,6 @@ pub enum DistError {
/// Version the project uses
your_version: semver::Version,
},

/// axoupdater can't be built for this target from this host
#[error("You've requested a cross-compile from {host} to {target}, but axoupdater can't be built for this target")]
#[diagnostic(help(
"Please either disable this target, or set `install-updater' to `false' in your config."
))]
AxoupdaterInvalidCross {
/// The host this build is on
host: TripleName,
/// The target this build is for
target: TripleName,
},
}

impl From<minijinja::Error> for DistError {
Expand Down
68 changes: 5 additions & 63 deletions cargo-dist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ use backend::{
self, macpkg::PkgInstallerInfo, msi::MsiInstallerInfo, HomebrewImpl, InstallerImpl,
},
};
use build::{
cargo::make_build_cargo_target_command,
generic::{build_generic_target, run_extra_artifacts_build},
};
use build::generic::{build_generic_target, run_extra_artifacts_build};
use build::{
cargo::{build_cargo_target, rustup_toolchain},
fake::{build_fake_cargo_target, build_fake_generic_target},
Expand All @@ -35,7 +32,6 @@ use config::{
ArtifactMode, ChecksumStyle, CompressionImpl, Config, DirtyMode, GenerateMode, ZipStyle,
};
use console::Term;
use platform::targets::TARGET_ARM64_WINDOWS;
use semver::Version;
use temp_dir::TempDir;
use tracing::info;
Expand Down Expand Up @@ -180,7 +176,6 @@ fn run_build_step(
const AXOUPDATER_ASSET_ROOT: &str =
"https://github.com/axodotdev/axoupdater/releases/latest/download";
const AXOUPDATER_MINIMUM_VERSION: &str = "0.7.0";
const AXOUPDATER_GIT_URL: &str = "https://github.com/axodotdev/axoupdater.git";

/// Fetches an installer executable and installs it in the expected target path.
pub fn fetch_updater(dist_graph: &DistGraph, updater: &UpdaterStep) -> DistResult<()> {
Expand All @@ -202,70 +197,17 @@ pub fn fetch_updater(dist_graph: &DistGraph, updater: &UpdaterStep) -> DistResul
// If we have a prebuilt asset, use it
if resp.status().is_success() {
fetch_updater_from_binary(dist_graph, updater, &expected_url)
// If we got a 404, there's no asset, so we have to build from source
// If we got a 404, report that there's no binary for this target
} else if resp.status() == axoasset::reqwest::StatusCode::NOT_FOUND {
fetch_updater_from_source(dist_graph, updater)
Err(DistError::NoAxoupdaterForTarget {
target: updater.target_triple.to_string(),
})
// Some unexpected result that wasn't 200 or 404
} else {
Err(DistError::AxoupdaterReleaseCheckFailed {})
}
}

/// Builds an installer executable from source and installs it in the expected target path.
pub fn fetch_updater_from_source(dist_graph: &DistGraph, updater: &UpdaterStep) -> DistResult<()> {
let (_tmp_dir, tmp_root) = create_tmp()?;

// cargo-xwin can't currently build one of axoupdater's dependencies:
// https://github.com/rust-cross/cargo-xwin/issues/76
let host = cargo_dist_schema::target_lexicon::HOST;
let target = updater.target_triple.parse()?;
if host != target && updater.target_triple == TARGET_ARM64_WINDOWS {
return Err(DistError::AxoupdaterInvalidCross {
host: TripleName::new(host.to_string()),
target: updater.target_triple.to_owned(),
});
}

let Some(git) = &dist_graph.tools.git else {
return Err(DistError::ToolMissing {
tool: "git".to_owned(),
});
};
// We can't use `cargo install` due to the cross-compile wrappers,
// so fetch the repo ahead of time.
let mut cmd = Cmd::new(&git.cmd, "fetch axoupdater");
cmd.arg("clone").arg(AXOUPDATER_GIT_URL).arg(&tmp_root);
cmd.run()?;

let features = CargoTargetFeatures {
default_features: true,
features: CargoTargetFeatureList::List(vec!["tls_native_roots".to_owned()]),
};
let step = CargoBuildStep {
target_triple: updater.target_triple.to_owned(),
features,
package: CargoTargetPackages::Workspace,
profile: "dist".to_string(),
rustflags: "".to_owned(),
expected_binaries: vec![],
working_dir: tmp_root.clone(),
};
let cargo = dist_graph.tools.cargo()?;
let mut cmd = make_build_cargo_target_command(&host, &cargo.cmd, "", &step, false)?;
cmd.arg("--bin").arg("axoupdater");

cmd.run()?;

// OK, now we have a binary in the tempdir
let mut source = tmp_root.join("target").join("release").join("axoupdater");
if updater.target_triple.is_windows() {
source.set_extension("exe");
}
LocalAsset::copy_file_to_file(source, dist_graph.target_dir.join(&updater.target_filename))?;

Ok(())
}

/// Creates a temporary directory, returning the directory and
/// its path as a Utf8PathBuf.
pub fn create_tmp() -> DistResult<(TempDir, Utf8PathBuf)> {
Expand Down

0 comments on commit dccb10a

Please sign in to comment.