Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions cargo-dist/src/config/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ pub struct DistMetadata {
#[serde(default)]
pub min_glibc_version: Option<MinGlibcVersion>,

/// Overrides for platform binaries, same syntax as min_glibc_version
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub binaries: Option<SortedMap<String, Vec<String>>>,

/// Whether to embed dependency information in the executable.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
Expand Down Expand Up @@ -552,6 +557,7 @@ impl DistMetadata {
github_build_setup: _,
mac_pkg_config: _,
min_glibc_version: _,
binaries: _,
cargo_auditable: _,
cargo_cyclonedx: _,
omnibor: _,
Expand Down Expand Up @@ -655,6 +661,7 @@ impl DistMetadata {
github_build_setup,
mac_pkg_config,
min_glibc_version,
binaries,
cargo_auditable,
cargo_cyclonedx,
omnibor,
Expand Down Expand Up @@ -854,6 +861,9 @@ impl DistMetadata {
if min_glibc_version.is_none() {
min_glibc_version.clone_from(&workspace_config.min_glibc_version);
}
if binaries.is_none() {
binaries.clone_from(&workspace_config.binaries);
}
if cargo_auditable.is_none() {
cargo_auditable.clone_from(&workspace_config.cargo_auditable);
}
Expand Down
5 changes: 4 additions & 1 deletion cargo-dist/src/config/v0_to_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl DistMetadata {
install_libraries,
github_build_setup,
min_glibc_version,
binaries,
cargo_auditable,
cargo_cyclonedx,
omnibor,
Expand All @@ -96,13 +97,15 @@ impl DistMetadata {
|| auto_includes.is_some()
|| windows_archive.is_some()
|| unix_archive.is_some()
|| package_libraries.is_some();
|| package_libraries.is_some()
|| binaries.is_some();
let archive_layer = needs_archive_layer.then_some(ArchiveLayer {
include,
auto_includes,
windows_archive,
unix_archive,
package_libraries,
binaries,
});
let needs_artifacts = archive_layer.is_some()
|| source_tarball.is_some()
Expand Down
11 changes: 11 additions & 0 deletions cargo-dist/src/config/v1/artifacts/archives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub struct ArchiveConfig {
pub unix_archive: ZipStyle,
/// Whether to include built libraries in the release archive
pub package_libraries: Vec<LibraryStyle>,
/// Binaries for a given platform
pub binaries: SortedMap<String, Vec<String>>,
}

/// archive config (raw from config file)
Expand Down Expand Up @@ -48,6 +50,10 @@ pub struct ArchiveLayer {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, with = "opt_string_or_vec")]
pub package_libraries: Option<Vec<LibraryStyle>>,

/// Binaries for a given platform
#[serde(skip_serializing_if = "Option::is_none")]
pub binaries: Option<SortedMap<String, Vec<String>>>,
}

impl ArchiveConfig {
Expand All @@ -59,6 +65,7 @@ impl ArchiveConfig {
windows_archive: ZipStyle::Zip,
unix_archive: ZipStyle::Tar(CompressionImpl::Xzip),
package_libraries: vec![],
binaries: SortedMap::default(),
}
}
}
Expand All @@ -73,13 +80,15 @@ impl ApplyLayer for ArchiveConfig {
windows_archive,
unix_archive,
package_libraries,
binaries,
}: Self::Layer,
) {
self.include.apply_val(include);
self.auto_includes.apply_val(auto_includes);
self.windows_archive.apply_val(windows_archive);
self.unix_archive.apply_val(unix_archive);
self.package_libraries.apply_val(package_libraries);
self.binaries.apply_val(binaries);
}
}
impl ApplyLayer for ArchiveLayer {
Expand All @@ -92,12 +101,14 @@ impl ApplyLayer for ArchiveLayer {
windows_archive,
unix_archive,
package_libraries,
binaries,
}: Self::Layer,
) {
self.include.apply_opt(include);
self.auto_includes.apply_opt(auto_includes);
self.windows_archive.apply_opt(windows_archive);
self.unix_archive.apply_opt(unix_archive);
self.package_libraries.apply_opt(package_libraries);
self.binaries.apply_opt(binaries);
}
}
2 changes: 2 additions & 0 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ fn get_new_dist_metadata(
github_build_setup: None,
mac_pkg_config: None,
min_glibc_version: None,
binaries: None,
cargo_auditable: None,
cargo_cyclonedx: None,
omnibor: None,
Expand Down Expand Up @@ -1051,6 +1052,7 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
bin_aliases: _,
system_dependencies: _,
github_build_setup: _,
binaries: _,
} = &meta;

// Forcibly inline the default install_path if not specified,
Expand Down
26 changes: 21 additions & 5 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ pub struct Release {
pub app_homepage_url: Option<String>,
/// A list of the app's keywords
pub app_keywords: Option<Vec<String>>,
/// The package this release is based on
pub pkg_idx: PackageIdx,
/// The version of the app
pub version: Version,
/// The unique id of the release (e.g. "my-app-v1.0.0")
Expand Down Expand Up @@ -1298,6 +1300,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
app_keywords,
version,
id,
pkg_idx,
global_artifacts: vec![],
bins: vec![],
cdylibs: vec![],
Expand Down Expand Up @@ -1328,20 +1331,33 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
cdylibs,
cstaticlibs,
config,
pkg_idx,
..
} = self.release_mut(to_release);
let static_assets = static_assets.clone();
let variant_id = format!("{release_id}-{target}");
info!("added variant {variant_id}");
let binaries_map = &config.artifacts.archives.binaries;

variants.push(idx);
targets.push(target.clone());

let mut packageables: Vec<(PackageIdx, String, BinaryKind)> = bins
.clone()
.into_iter()
.map(|(idx, b)| (idx, b, BinaryKind::Executable))
.collect();
// Apply binary list overrides
let mapped_bins = binaries_map
.get(target.as_str())
.or_else(|| binaries_map.get("*"));
let mut packageables: Vec<(PackageIdx, String, BinaryKind)> =
if let Some(mapped_bins) = mapped_bins {
mapped_bins
.iter()
.map(|b| (*pkg_idx, b.to_string(), BinaryKind::Executable))
.collect()
} else {
bins.clone()
.into_iter()
.map(|(idx, b)| (idx, b, BinaryKind::Executable))
.collect()
};

// If we're not packaging libraries here, avoid chaining them
// into the list we're iterating over
Expand Down
44 changes: 44 additions & 0 deletions cargo-dist/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,50 @@ install-location = "/opt/axolotlsay"
})
}

#[test]
fn axolotlsay_basic_bins() -> Result<(), miette::Report> {
let test_name = _function_name!();
AXOLOTLSAY.run_test(|ctx| {
let dist_version = ctx.tools.cargo_dist.version().unwrap();
ctx.patch_cargo_toml(format!(r#"
[workspace.metadata.dist]
cargo-dist-version = "{dist_version}"
installers = ["shell", "powershell", "homebrew", "npm", "msi", "pkg"]
tap = "axodotdev/homebrew-packages"
publish-jobs = ["homebrew", "npm"]
targets = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu", "aarch64-apple-darwin"]
install-success-msg = ">o_o< everything's installed!"
ci = ["github"]
unix-archive = ".tar.gz"
windows-archive = ".tar.gz"
npm-scope ="@axodotdev"

[workspace.metadata.dist.binaries]
"*" = ["axolotlsay"]
x86_64-pc-windows-msvc = ["axlotolsay", "axolotlsayw"]

[package.metadata.wix]
upgrade-guid = "B36177BE-EA4D-44FB-B05C-EDDABDAA95CA"
path-guid = "BFD25009-65A4-4D1E-97F1-0030465D90D6"

[package.metadata.dist.mac-pkg-config]
identifier = "dev.axo.axolotsay"

"#
))?;

// Run generate to make sure stuff is up to date before running other commands
let ci_result = ctx.cargo_dist_generate(test_name)?;
let ci_snap = ci_result.check_all()?;
// Do usual build+plan checks
let main_result = ctx.cargo_dist_build_and_plan(test_name)?;
let main_snap = main_result.check_all(&ctx, ".cargo/bin/")?;
// snapshot all
main_snap.join(ci_snap).snap();
Ok(())
})
}

#[test]
fn axolotlsay_custom_formula() -> Result<(), miette::Report> {
let test_name = _function_name!();
Expand Down
Loading
Loading