Skip to content

Commit

Permalink
Add a cargo-dist-url-override key
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Nov 5, 2024
1 parent 06c6ee4 commit f4a4726
Show file tree
Hide file tree
Showing 65 changed files with 1,168 additions and 322 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# we specify bash to get pipefail; it guards against the `curl` command
# failing. otherwise `sh` won't catch that `curl` returned non-0
shell: bash
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.24.0-prerelease.2/cargo-dist-installer.sh | sh"
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.24.1/cargo-dist-installer.sh | sh"
- name: Cache dist
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -122,7 +122,8 @@ jobs:
with:
submodules: recursive
- name: Install dist
run: ${{ matrix.install_dist }}
shell: ${{ matrix.install_dist.shell }}
run: ${{ matrix.install_dist.run }}
# Get the dist-manifest
- name: Fetch local artifacts
uses: actions/download-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 36 additions & 2 deletions cargo-dist-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ pub struct GithubMatrixEntry {
#[serde(skip_serializing_if = "Option::is_none")]
pub runner: Option<GithubRunner>,
/// Expression to execute to install dist
#[serde(skip_serializing_if = "Option::is_none")]
pub install_dist: Option<String>,
pub install_dist: GhaRunStep,
/// Arguments to pass to dist
#[serde(skip_serializing_if = "Option::is_none")]
pub dist_args: Option<String>,
Expand All @@ -319,6 +318,41 @@ pub struct GithubMatrixEntry {
pub cache_provider: Option<String>,
}

/// A GitHub Actions "run" step, either bash or powershell
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
// this mirrors GHA's structure, see
// * <https://serde.rs/enum-representations.html>
// * <https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell>
#[serde(tag = "shell", content = "run")]
pub enum GhaRunStep {
/// see [`DashScript`]
#[serde(rename = "sh")]
Dash(DashScript),
/// see [`PowershellScript`]
#[serde(rename = "pwsh")]
Powershell(PowershellScript),
}

impl From<DashScript> for GhaRunStep {
fn from(bash: DashScript) -> Self {
Self::Dash(bash)
}
}

impl From<PowershellScript> for GhaRunStep {
fn from(powershell: PowershellScript) -> Self {
Self::Powershell(powershell)
}
}

declare_strongly_typed_string! {
/// A bit of shell script (that can run with `/bin/sh`), ran on CI runners. Can be multi-line.
pub struct DashScript => &DashScriptRef;

/// A bit of powershell script, ran on CI runners. Can be multi-line.
pub struct PowershellScript => &PowershellScriptRef;
}

/// Type of job to run on pull request
#[derive(
Debug, Copy, Clone, Serialize, Deserialize, JsonSchema, Default, PartialEq, Eq, PartialOrd, Ord,
Expand Down
53 changes: 50 additions & 3 deletions cargo-dist-schema/src/snapshots/cargo_dist_schema__emit.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ lazy_static.workspace = true
current_platform.workspace = true
color-backtrace.workspace = true
backtrace.workspace = true
schemars.workspace = true

[dev-dependencies]
insta.workspace = true
Expand Down
52 changes: 32 additions & 20 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use axoasset::{LocalAsset, SourceFile};
use axoprocess::Cmd;
use camino::{Utf8Path, Utf8PathBuf};
use cargo_dist_schema::{
GithubMatrix, GithubMatrixEntry, GithubRunner, GithubRunnerRef, TargetTriple, TargetTripleRef,
GhaRunStep, GithubMatrix, GithubMatrixEntry, GithubRunner, GithubRunnerRef, TargetTriple,
TargetTripleRef,
};
use serde::{Deserialize, Serialize};
use tracing::warn;
Expand All @@ -24,24 +25,30 @@ use crate::{
DistError, DistGraph, SortedMap, SortedSet,
};

use super::{DistInstallSettings, DistInstallStrategy};

#[cfg(not(windows))]
const GITHUB_CI_DIR: &str = ".github/workflows/";
#[cfg(windows)]
const GITHUB_CI_DIR: &str = r".github\workflows\";
const GITHUB_CI_FILE: &str = "release.yml";

/// Info about running dist in Github CI
///
/// THESE FIELDS ARE LOAD-BEARING because they're used in the templates.
#[derive(Debug, Serialize)]
pub struct GithubCiInfo {
/// Cached path to github CI workflows dir
#[serde(skip_serializing)]
pub github_ci_workflow_dir: Utf8PathBuf,
/// Version of rust toolchain to install (deprecated)
pub rust_version: Option<String>,
/// expression to use for installing dist via shell script
pub install_dist_sh: String,
/// expression to use for installing dist via powershell script
pub install_dist_ps1: String,

/// How to install dist when "coordinating" (plan, global build, etc.)
pub dist_install_for_coordinator: GhaRunStep,
/// Our install strategy for dist itself
pub dist_install_strategy: DistInstallStrategy,

/// Whether to fail-fast
pub fail_fast: bool,
/// Whether to cache builds
Expand Down Expand Up @@ -216,8 +223,12 @@ impl GithubCiInfo {
}

// Get the platform-specific installation methods
let install_dist_sh = super::install_dist_sh_for_version(dist_version);
let install_dist_ps1 = super::install_dist_ps1_for_version(dist_version);
let dist_install_strategy = (DistInstallSettings {
version: dist_version,
url_override: dist.config.dist_url_override.as_deref(),
})
.install_strategy();

let hosting_providers = dist
.hosting
.as_ref()
Expand Down Expand Up @@ -245,7 +256,7 @@ impl GithubCiInfo {
cache_provider: cache_provider_for_runner(global_runner),
runner: Some(global_runner.to_owned()),
dist_args: Some("--artifacts=global".into()),
install_dist: Some(install_dist_sh.clone()),
install_dist: dist_install_strategy.sh().into(),
packages_install: None,
};

Expand Down Expand Up @@ -300,8 +311,7 @@ impl GithubCiInfo {
};
for (runner, targets) in local_runs {
use std::fmt::Write;
let install_dist =
install_dist_for_targets(&targets, &install_dist_sh, &install_dist_ps1);
let install_dist = install_dist_for_targets(&targets, &dist_install_strategy);
let mut dist_args = String::from("--artifacts=local");
for target in &targets {
write!(dist_args, " --target={target}").unwrap();
Expand All @@ -311,7 +321,7 @@ impl GithubCiInfo {
cache_provider: cache_provider_for_runner(&runner),
runner: Some(runner),
dist_args: Some(dist_args),
install_dist: Some(install_dist.to_owned()),
install_dist: install_dist.to_owned(),
packages_install: package_install_for_targets(&targets, &dependencies),
});
}
Expand All @@ -334,8 +344,8 @@ impl GithubCiInfo {
github_ci_workflow_dir,
tag_namespace,
rust_version,
install_dist_sh,
install_dist_ps1,
dist_install_for_coordinator: dist_install_strategy.sh().into(),
dist_install_strategy,
fail_fast,
cache_builds,
build_local_artifacts,
Expand Down Expand Up @@ -621,18 +631,20 @@ fn github_runner_for_target(
/// Select the dist installer approach for a given Github Runner
fn install_dist_for_targets<'a>(
targets: &'a [&'a TargetTripleRef],
install_sh: &'a str,
install_ps1: &'a str,
) -> &'a str {
install_strategy: &'a DistInstallStrategy,
) -> GhaRunStep {
// FIXME: when doing cross-compilation, `host != runner`, and we should
// pick something that runs on the host. We need knowledge about "which
// platform is this GitHub runner" ahead of time to do that, though.

for target in targets {
if target.is_linux() || target.is_apple() {
return install_sh;
return install_strategy.sh().into();
} else if target.is_windows() {
return install_ps1;
return install_strategy.powershell().into();
}
}

unreachable!("internal error: unknown target triple!?")
panic!("unsupported target triple(s) {targets:?}");
}

fn brewfile_from(packages: &[String]) -> String {
Expand Down
Loading

0 comments on commit f4a4726

Please sign in to comment.