diff --git a/Cargo.lock b/Cargo.lock index 5c752cff..88bec64a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,9 +406,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.72" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -658,7 +658,7 @@ dependencies = [ "tempfile", "time", "toml", - "toml_edit 0.22.14", + "toml_edit", "tracing", "tracing-chrome", "tracing-subscriber", @@ -755,10 +755,10 @@ dependencies = [ "serde_json", "target", "toml", - "toml_edit 0.22.14", + "toml_edit", "try-lazy-init", "walkdir", - "zip 1.1.4", + "zip", ] [[package]] @@ -908,15 +908,6 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cbd0f76e066e64fdc5631e3bb46381254deab9ef1158292f27c8c57e3bf3fe59" -[[package]] -name = "cmake" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" -dependencies = [ - "cc", -] - [[package]] name = "color-print" version = "0.3.6" @@ -1582,7 +1573,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", - "libz-ng-sys", "libz-sys", "miniz_oxide", ] @@ -2759,9 +2749,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3935c160d00ac752e09787e6e6bfc26494c2183cc922f1bc678a60d4733bc2" +checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545" [[package]] name = "httpdate" @@ -3308,16 +3298,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libz-ng-sys" -version = "1.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6409efc61b12687963e602df8ecf70e8ddacf95bc6576bcf16e3ac6328083c5" -dependencies = [ - "cmake", - "libc", -] - [[package]] name = "libz-sys" version = "1.1.18" @@ -3703,27 +3683,6 @@ dependencies = [ "libc", ] -[[package]] -name = "num_enum" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "num_threads" version = "0.1.7" @@ -3752,9 +3711,9 @@ dependencies = [ [[package]] name = "object" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -4497,15 +4456,6 @@ dependencies = [ "elliptic-curve", ] -[[package]] -name = "proc-macro-crate" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" -dependencies = [ - "toml_edit 0.21.1", -] - [[package]] name = "proc-macro2" version = "1.0.85" @@ -5304,7 +5254,7 @@ dependencies = [ "symbolic-ppdb", "thiserror", "wasmparser", - "zip 2.1.1", + "zip", "zstd", ] @@ -5617,7 +5567,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.14", + "toml_edit", ] [[package]] @@ -5629,17 +5579,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" -dependencies = [ - "indexmap 2.2.6", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.14" @@ -6524,6 +6463,20 @@ name = "zeroize" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] [[package]] name = "zerovec" @@ -6549,9 +6502,9 @@ dependencies = [ [[package]] name = "zip" -version = "1.1.4" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cc23c04387f4da0374be4533ad1208cbb091d5c11d070dfef13676ad6497164" +checksum = "1dd56a4d5921bc2f99947ac5b3abe5f510b1be7376fdc5e9fce4a23c6a93e87c" dependencies = [ "aes", "arbitrary", @@ -6565,32 +6518,17 @@ dependencies = [ "hmac", "indexmap 2.2.6", "lzma-rs", - "num_enum", + "memchr", "pbkdf2", + "rand", "sha1", "thiserror", "time", + "zeroize", "zopfli", "zstd", ] -[[package]] -name = "zip" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd56a4d5921bc2f99947ac5b3abe5f510b1be7376fdc5e9fce4a23c6a93e87c" -dependencies = [ - "arbitrary", - "crc32fast", - "crossbeam-utils", - "displaydoc", - "flate2", - "indexmap 2.2.6", - "memchr", - "thiserror", - "zopfli", -] - [[package]] name = "zopfli" version = "0.8.1" diff --git a/cargo/Cargo.toml b/cargo/Cargo.toml index 3a13274a..cd727bdd 100644 --- a/cargo/Cargo.toml +++ b/cargo/Cargo.toml @@ -43,7 +43,7 @@ toml.workspace = true toml_edit = { version = "0.22", features = ["serde"] } regex.workspace = true byteorder = "1.5" -zip = { version = "1.1", features = ["time"] } +zip = { version = "2.1", features = ["time"] } walkdir = "2.5" anyhow = "1.0" diff --git a/cargo/src/assets/plan.rs b/cargo/src/assets/plan.rs index aca5e872..168c0826 100644 --- a/cargo/src/assets/plan.rs +++ b/cargo/src/assets/plan.rs @@ -757,3 +757,7 @@ pub enum AssetKind { Package, Dev, } + +impl AssetKind { + pub fn is_dev(&self) -> bool { matches!(self, Self::Dev) } +} diff --git a/cargo/src/main.rs b/cargo/src/main.rs index b0462f05..e636295b 100644 --- a/cargo/src/main.rs +++ b/cargo/src/main.rs @@ -83,15 +83,13 @@ fn execute(config: &Config) -> CargoResult<()> { cli::cmd::Cmd::Package => { let deps_tree = crate::utils::cargo::meta_deps::meta_deps(config)?; - let assets_new = assets::proto::build_all(config, &deps_tree)?; - - let assets = assets::build(config)?; + let assets = assets::proto::build_all(config, &deps_tree)?; let products = build::build(config)?; - log::debug!("assets artifacts: old:{} / new:{}", assets.len(), assets_new.len()); + log::debug!("assets artifacts: {}", assets.len()); log::debug!("build artifacts: {}", products.len()); - package::build_all(config, assets, assets_new, products)?; + package::build_all(config, assets, products)?; }, cli::cmd::Cmd::Run => { @@ -150,10 +148,9 @@ fn execute(config: &Config) -> CargoResult<()> { } let deps_tree = crate::utils::cargo::meta_deps::meta_deps(config)?; - let assets_new = assets::proto::build_all(config, &deps_tree)?; // build requested package(s): - let assets = assets::build(config)?; + let assets = assets::proto::build_all(config, &deps_tree)?; let mut products = build::build(config)?; // filter products with expected: @@ -178,7 +175,7 @@ fn execute(config: &Config) -> CargoResult<()> { }) .count(); - let packages = package::build_all(config, assets, assets_new, products)?; + let packages = package::build_all(config, assets, products)?; match packages.len() { 1 => (), 0 => bail!("No packages have been produced, nothing to run."), @@ -186,8 +183,7 @@ fn execute(config: &Config) -> CargoResult<()> { } let package = packages.first().unwrap(); - config.log() - .build_finished(true, Some(package.package.package_id())); + config.log().build_finished(true, Some(package.package_id)); { diff --git a/cargo/src/package/mod.rs b/cargo/src/package/mod.rs index a3b033cc..de9185bb 100644 --- a/cargo/src/package/mod.rs +++ b/cargo/src/package/mod.rs @@ -7,6 +7,7 @@ use std::process::Command; use anyhow::anyhow; use anyhow::bail; +use cargo::core::PackageId; use cargo::CargoResult; use cargo::core::Package; use cargo::core::compiler::CompileKind; @@ -20,14 +21,11 @@ use playdate::layout::Layout; use playdate::layout::Name; use playdate::manifest::format::ManifestFmt; use playdate::manifest::PackageSource; -use playdate::metadata::format::Metadata; use playdate::metadata::validation::Validate; use playdate::metadata::validation::ValidateCrate; use crate::assets::proto::AssetsArtifactsNew; -use crate::assets::AssetsArtifact; -use crate::assets::AssetsArtifacts; -use crate::assets::playdate_metadata; +use crate::assets::proto::AssetsArtifact as AssetsArtifactNew; use crate::build::BuildProduct; use crate::config::Config; use crate::layout::CrossTargetLayout; @@ -35,26 +33,28 @@ use crate::layout::LayoutLockable; use crate::layout::ForTargetLayout; use crate::proc::logging::cmd_logged; use crate::proc::reader::format::ArtifactProfile; +use crate::utils::cargo::meta_deps::RootNode; use crate::utils::path::AsRelativeTo; mod ar; #[derive(Debug)] -pub struct Product<'p> { - pub package: &'p Package, +pub struct Product { + pub package_id: PackageId, pub crate_types: Vec, pub targets: Vec, + /// Build-product name pub name: String, + /// Path of produced artifact - pdx-dir or zip-file pub path: PathBuf, } pub fn build_all<'b>(config: &'_ Config, - assets: AssetsArtifacts<'_>, - assets_new: AssetsArtifactsNew<'_, '_>, + assets: AssetsArtifactsNew<'_, '_>, products: Vec>) - -> CargoResult>> { + -> CargoResult> { let products: Vec = products.into_iter().flat_map(TryInto::try_into).collect(); let mut targets = HashMap::<_, Vec<_>>::new(); @@ -81,38 +81,36 @@ pub fn build_all<'b>(config: &'_ Config, } ); - let (root, assets_ng) = assets_new.iter() - .find(|(r, _)| { - let unit = r.node().unit(); - unit.package_id == package.package_id() && - unit.platform == products[0].ck && - unit.target.crate_types.contains(&products[0].src_ct) && - unit.target.name == products[0].name - }) - .ok_or_else(|| { - let ck: Cow<_> = match products[0].ck { - CompileKind::Host => "host".into(), - CompileKind::Target(ref kind) => kind.short_name().into(), - }; - anyhow!( - "No assets artifacts for ({}) {}::{} for {ck}", - &products[0].src_ct, - package.package_id(), - products[0].name, + let (root, assets_ng) = assets.iter() + .find(|(r, _)| { + let unit = r.node().unit(); + unit.package_id == package.package_id() && + unit.platform == products[0].ck && + unit.target.crate_types.contains(&products[0].src_ct) && + unit.target.name == products[0].name + }) + .ok_or_else(|| { + let ck: Cow<_> = match products[0].ck { + CompileKind::Host => "host".into(), + CompileKind::Target(ref kind) => kind.short_name().into(), + }; + anyhow!( + "No assets artifacts for ({}) {}::{} for {ck}", + &products[0].src_ct, + package.package_id(), + products[0].name, ) - })?; + })?; match products.len() { 0 => unreachable!("impossible len=0"), 1 => { - let assets = assets.get(package); let product = products.pop().unwrap(); - let result = package_single_target(config, product, assets)?; + let result = package_single_target(config, product, root, assets_ng)?; results.push(result); }, _ => { - let assets = assets.get(package); - let result = package_multi_target(config, package, products, assets)?; + let result = package_multi_target(config, package, products, root, assets_ng)?; results.push(result); }, } @@ -122,10 +120,11 @@ pub fn build_all<'b>(config: &'_ Config, } -fn package_single_target<'p>(config: &Config, - product: SuccessfulBuildProduct<'p>, - assets: Option<&AssetsArtifact>) - -> CargoResult> { +fn package_single_target<'p, 'art>(config: &Config, + product: SuccessfulBuildProduct<'p>, + root: &RootNode<'_>, + assets: impl Iterator) + -> CargoResult { let presentable_name = product.presentable_name(); config.log().status( "Packaging", @@ -135,18 +134,16 @@ fn package_single_target<'p>(config: &Config, ), ); - if let Some(assets) = assets { - assert_eq!(assets.package_id, product.package.package_id()); - log::debug!("Preparing assets for packaging {}", product.presentable_name()); - - prepare_assets( - config, - assets, - product.example, - product.layout.build(), - true, - product.layout.root(), - )?; + + if config.compile_options.build_config.force_rebuild { + // TODO: clean entire product.layout.build() if force rebuild requested + } + + + for art in assets { + log::debug!("Packaging assets {:?} {}", art.kind, product.presentable_name()); + + prepare_assets(config, art, product.layout.build(), true, product.layout.root())?; } // manifest: @@ -156,7 +153,7 @@ fn package_single_target<'p>(config: &Config, config, &product.layout, product.package, - assets, + root.as_source(), cargo_target, product.example, )?; @@ -171,7 +168,7 @@ fn package_single_target<'p>(config: &Config, } let result = Product { name: product.name, - package: product.package, + package_id: product.package.package_id(), crate_types: vec![product.src_ct.clone()], targets: vec![product.ck], path: artifact.to_path_buf() }; @@ -189,11 +186,12 @@ fn package_single_target<'p>(config: &Config, /// So one executable and one or two dylibs. /// /// __Can't mix macos dylib with linux dylib in a one package.__ -fn package_multi_target<'p>(config: &Config, - package: &'p Package, - products: Vec, - assets: Option<&AssetsArtifact>) - -> CargoResult> { +fn package_multi_target<'p, 'art>(config: &Config, + package: &'p Package, + products: Vec, + root: &RootNode<'_>, + assets: impl Iterator) + -> CargoResult { let src_cts = products.iter() .map(|p| format!("{}", p.src_ct)) .collect::>() @@ -273,15 +271,14 @@ fn package_multi_target<'p>(config: &Config, let mut layout = CrossTargetLayout::new(config, package.package_id(), Some(layout_target_name))?.lock(config.workspace .gctx())?; - if let Some(assets) = assets { - debug_assert_eq!( - layout.as_ref().assets_layout(config).root(), - assets.layout.root(), - "wrong layout root" - ); - } crate::layout::Layout::prepare(&mut layout.as_mut())?; + + if config.compile_options.build_config.force_rebuild { + // TODO: clean entire product.layout.build() if force rebuild requested + } + + let mut dev = Default::default(); for product in &products { log::debug!("Preparing binaries for packaging {}", product.presentable_name()); @@ -296,18 +293,25 @@ fn package_multi_target<'p>(config: &Config, // Then the same as for single-product package: - if let Some(assets) = assets { - log::debug!("Preparing assets for packaging {}", assets.package_id.name()); - assert_eq!(package.package_id(), assets.package_id, "package must be same"); - prepare_assets( - config, - assets, - dev.is_some(), - layout.build(), - true, - layout.as_inner().target(), - )?; + let mut was_dev = false; + for artifact in assets { + log::debug!( + "Packaging assets {:?} {}", + artifact.kind, + artifact.package_id.name() + ); + + debug_assert_eq!( + layout.as_ref().assets_layout(config).root(), + artifact.layout.root(), + "wrong layout root" + ); + + was_dev = was_dev || artifact.kind.is_dev(); + + prepare_assets(config, artifact, layout.build(), true, layout.as_inner().target())?; } + assert_eq!(dev.is_some(), was_dev); // manifest: let cargo_target = @@ -317,7 +321,7 @@ fn package_multi_target<'p>(config: &Config, config, &layout, package, - assets, + root.as_source(), cargo_target, products[0].example, )?; @@ -336,7 +340,7 @@ fn package_multi_target<'p>(config: &Config, soft_link_checked(&artifact, &link, true, product.layout.root())?; } - let result = Product { package, + let result = Product { package_id: package.package_id(), name: products[0].name.clone(), crate_types: products.iter().map(|p| p.src_ct.clone()).collect(), targets: products.iter().map(|p| p.ck).collect(), @@ -348,7 +352,7 @@ fn package_multi_target<'p>(config: &Config, fn build_manifest(config: &Config, layout: &Layout, package: &Package, - assets: Option<&AssetsArtifact>, + source: impl PackageSource, cargo_target: Option>, dev: bool) -> CargoResult<()> { @@ -366,42 +370,24 @@ fn build_manifest(config: &Config, config.log().warn(msg); } }; - let log_src_problem = |problem: Problem| { - let msg = "Manifest validation".to_string(); - log_problem(&msg, problem) - }; - let log_meta_problem = |problem: Problem| { - let msg = "Metadata validation".to_string(); - log_problem(&msg, problem) - }; + let log_src_problem = |problem: Problem| log_problem("Manifest validation", problem); + let log_meta_problem = |problem: Problem| log_problem("Metadata validation", problem); - let validate = |src: &ManifestSource| { - if let Some(target) = &cargo_target { - src.validate_for(target) - .into_iter() - // .filter(Problem::is_err) - .for_each(log_meta_problem); - } else { - src.validate() - .into_iter() - // .filter(Problem::is_err) - .for_each(log_meta_problem); - } - }; - let manifest = if let Some(metadata) = assets.and_then(|a| a.metadata.as_ref()) { - let source = ManifestSource::new(package, metadata.into()); - // This validation not needed at this step. May be earlier: - validate(&source); - source.manifest_override_or_crate(cargo_target.as_deref(), dev) + // validate the source: + if let Some(target) = &cargo_target { + source.validate_for(target) + .into_iter() + // .filter(Problem::is_err) + .for_each(log_meta_problem); } else { - let metadata = playdate_metadata(package); - let source = ManifestSource::new(package, metadata.as_ref()); - // This validation not needed at this step. May be earlier: - validate(&source); - source.manifest_override_or_crate(cargo_target.as_deref(), dev) - }; + source.validate() + .into_iter() + // .filter(Problem::is_err) + .for_each(log_meta_problem); + } + let manifest = source.manifest_override_or_crate(cargo_target.as_deref(), dev); // validation, lints manifest.validate().into_iter().for_each(log_src_problem); @@ -456,8 +442,7 @@ fn execute_pdc<'l, Layout: playdate::layout::Layout>(config: &Config, fn prepare_assets>(config: &Config, - assets: &AssetsArtifact, - dev: bool, + assets: &AssetsArtifactNew, dst: Dst, overwrite: bool, root: impl AsRef) @@ -466,6 +451,8 @@ fn prepare_assets>(config: &Config, // - `assets.layout.build` points to pre-built assets, but that can fail // - `assets.layout.assets` points to original assets, so use it as fallback + let dev = assets.kind.is_dev(); + let filter_hidden = |path: &PathBuf| { if let Some(filename) = path.file_name() { !filename.starts_with(".") @@ -501,25 +488,15 @@ fn prepare_assets>(config: &Config, Ok(()) }; + let (assets_src, assets_build) = if dev { + (assets.layout.assets_dev(), assets.layout.build_dev()) + } else { + (assets.layout.assets(), assets.layout.build()) + }; - // Main assets: - let files: Vec<_> = select_files_in(&assets.layout.build(), &assets.layout.assets())?; + let files: Vec<_> = select_files_in(&assets_build, &assets_src)?; link_assets(files)?; - // Dev assets: - if dev { - let assets_dev = assets.layout.assets_dev(); - if assets_dev.exists() { - let files: Vec<_> = select_files_in(&assets.layout.build_dev(), &assets_dev)?; - link_assets(files)?; - } else { - // That's OK, dev-assets can be missing, we doesn't create dir without need. - log::debug!( - "Asset (dev) not found at {}", - assets_dev.as_relative_to_root(config).display() - ); - } - } Ok(()) } @@ -580,70 +557,3 @@ impl<'cfg> TryFrom> for SuccessfulBuildProduct<'cfg> { } } } - - -struct ManifestSource<'cfg, 'm> { - package: &'cfg Package, - authors: Vec<&'cfg str>, - bins: Vec<&'cfg str>, - examples: Vec<&'cfg str>, - metadata: Option<&'m Metadata>, -} - -impl<'cfg, 'm> ManifestSource<'cfg, 'm> { - fn new(package: &'cfg Package, metadata: Option<&'m Metadata>) -> Self { - log::debug!("new manifest-source for {}", package.package_id()); - - let mut bins = Vec::new(); - let mut examples = Vec::new(); - - package.targets() - .iter() - .inspect(|t| log::trace!("target: {} ({:?})", t.description_named(), t.crate_name())) - .filter(|t| !t.is_custom_build()) - .for_each(|t| { - if t.is_bin() { - bins.push(t.name()); - log::debug!("+bin: {}", t.description_named()); - } else if t.is_example() { - examples.push(t.name()); - log::debug!("+example: {}", t.description_named()); - } - }); - - Self { authors: package.manifest() - .metadata() - .authors - .iter() - .map(|s| s.as_str()) - .collect(), - bins, - examples, - package, - metadata } - } -} - -impl<'cfg> PackageSource for ManifestSource<'cfg, '_> { - type Authors = [&'cfg str]; - type Metadata = Metadata; - - fn name(&self) -> Cow { self.package.name().as_str().into() } - fn authors(&self) -> &[&'cfg str] { &self.authors } - fn version(&self) -> Cow { self.package.version().to_string().into() } - fn description(&self) -> Option> { - self.package - .manifest() - .metadata() - .description - .as_deref() - .map(|s: &str| s.into()) - } - - fn bins(&self) -> &[&str] { &self.bins } - fn examples(&self) -> &[&str] { &self.examples } - - fn metadata(&self) -> Option<&Self::Metadata> { self.metadata } - - fn manifest_path(&self) -> Cow { Cow::Borrowed(self.package.manifest_path()) } -}