From 715232179d893d4d349275339715ef7d7f33c842 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Mon, 16 Dec 2024 18:49:45 +0800 Subject: [PATCH 1/5] Fixed regex for 'CPU features' --- tests/integration_snapshots.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_snapshots.rs b/tests/integration_snapshots.rs index e482100a..36c8c4be 100644 --- a/tests/integration_snapshots.rs +++ b/tests/integration_snapshots.rs @@ -76,7 +76,7 @@ fn bugreport() { settings.add_filter(r"Architecture: \w+", "Architecture: [ARCH]"); settings.add_filter(r"Pointer width: \d+", "Pointer width: [WIDTH]"); settings.add_filter(r"Endian: \w+", "Endian: [ENDIAN]"); - settings.add_filter(r"CPU features: [\w,-]+", "CPU features: [FEATURES]"); + settings.add_filter(r"CPU features: [\w,-\.\d]+", "CPU features: [FEATURES]"); settings.add_filter(r"Host: [\w-]+", "Host: [HOST_TRIPLE]"); // this should be serialized TOML From 696d91a2d92fc349f706245ce913fcbc8178f71d Mon Sep 17 00:00:00 2001 From: Andrew Burkett Date: Wed, 25 Sep 2024 09:46:47 -0700 Subject: [PATCH 2/5] Add third party registry support This adds a `--registry` command line flag to the check release capabilities. The argument to the flag is the name of the registry to use to lookup the crates when using the default behavior or --baseline-version. If left unset, the default behavior remains of --checking crates.io. --- src/config.rs | 16 +++++++++++ src/main.rs | 9 ++++++ src/rustdoc_cmd.rs | 0 src/rustdoc_gen.rs | 72 ++++++++++++++++++++++++++++++---------------- 4 files changed, 73 insertions(+), 24 deletions(-) create mode 100644 src/rustdoc_cmd.rs diff --git a/src/config.rs b/src/config.rs index 860120f8..4ed4531a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -16,6 +16,8 @@ pub struct GlobalConfig { stdout: AutoStream>, stderr: AutoStream>, feature_flags: HashSet, + /// Registry name to look up crates in + registry: Option, } impl Default for GlobalConfig { @@ -41,6 +43,7 @@ impl GlobalConfig { stdout: AutoStream::new(Box::new(std::io::stdout()), stdout_choice), stderr: AutoStream::new(Box::new(std::io::stderr()), stderr_choice), feature_flags: HashSet::new(), + registry: None, } } @@ -316,6 +319,19 @@ impl GlobalConfig { pub fn feature_flags(&self) -> &HashSet { &self.feature_flags } + + /// Set (overwrite) the name of the registry to use for crate lookup + #[inline] + pub fn set_registry(&mut self, registry: String) -> &mut Self { + self.registry = Some(registry); + self + } + + /// Return the name of the registry to use for crate lookup + #[inline] + pub fn registry(&self) -> Option<&str> { + self.registry.as_deref() + } } /// A feature flag for gating unstable `cargo-semver-checks` features. diff --git a/src/main.rs b/src/main.rs index ef133cfb..05f6a764 100644 --- a/src/main.rs +++ b/src/main.rs @@ -156,6 +156,10 @@ fn main() { None => args.check_release, }; + if let Some(registry) = &check_release.registry { + config.set_registry(registry.clone()); + } + let check: cargo_semver_checks::Check = check_release.into(); let report = exit_on_error(config.is_error(), || check.check_release(&mut config)); @@ -532,6 +536,11 @@ struct CheckRelease { #[arg(long = "target")] build_target: Option, + /// Name of registry to use for crate lookups. Used with default behavior + /// and with `--baseline-version`. + #[arg(long = "registry")] + registry: Option, + #[clap(flatten)] unstable_options: UnstableOptions, } diff --git a/src/rustdoc_cmd.rs b/src/rustdoc_cmd.rs new file mode 100644 index 00000000..e69de29b diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index eadb1f75..632c35d7 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -16,6 +16,9 @@ use crate::GlobalConfig; pub(crate) enum CrateSource<'a> { Registry { crate_: &'a tame_index::IndexVersion, + /// The url of the registry index that holds the specified crate + index_url: String, + version: String, }, ManifestPath { manifest: &'a Manifest, @@ -548,6 +551,8 @@ pub(crate) struct RustdocFromRegistry { target_root: PathBuf, version: Option, index: tame_index::index::ComboIndex, + /// The url of the index for the given registry + index_url: String, } impl core::fmt::Debug for RustdocFromRegistry { @@ -562,32 +567,46 @@ impl core::fmt::Debug for RustdocFromRegistry { impl RustdocFromRegistry { pub fn new(target_root: &std::path::Path, config: &mut GlobalConfig) -> anyhow::Result { - let index_url = tame_index::IndexUrl::crates_io( - // This is the config root, where .cargo/config.toml configuration files - // are crawled to determine if crates.io has been source replaced - // - // if not specified it defaults to the current working directory, - // which is the same default that cargo uses, though note this can be - // extremely confusing if one can specify the manifest path of the - // crate from a different current working directory, though AFAICT - // this is not how this binary works - None, - // If set this overrides the CARGO_HOME that is used for both finding - // the "global" default config if not overriden during directory - // traversal to the root, as well as where the various registry - // indices/git sources are rooted. This is generally only useful - // for testing - None, - // If set, overrides the version of the cargo binary used, this is used - // as a fallback to determine if the version is 1.70.0+, which means - // the default crates.io registry to use is the sparse registry, else - // it is the old git registry - None, - ) - .context("failed to obtain crates.io url")?; + let index_url = match config.registry() { + Some(registry_name) => { + tame_index::IndexUrl::for_registry_name( + // No need to override the config root. See comment below for more information. + None, + // No need to override the cargo home. See comment below for more information. + None, + registry_name, + ) + .with_context(|| format!("failed to obtain url for registry '{}'", registry_name))? + } + None => tame_index::IndexUrl::crates_io( + // This is the config root, where .cargo/config.toml configuration files + // are crawled to determine if crates.io has been source replaced + // + // if not specified it defaults to the current working directory, + // which is the same default that cargo uses, though note this can be + // extremely confusing if one can specify the manifest path of the + // crate from a different current working directory, though AFAICT + // this is not how this binary works + None, + // If set this overrides the CARGO_HOME that is used for both finding + // the "global" default config if not overriden during directory + // traversal to the root, as well as where the various registry + // indices/git sources are rooted. This is generally only useful + // for testing + None, + // If set, overrides the version of the cargo binary used, this is used + // as a fallback to determine if the version is 1.70.0+, which means + // the default crates.io registry to use is the sparse registry, else + // it is the old git registry + None, + ) + .context("failed to obtain crates.io url")?, + }; use tame_index::index::{self, ComboIndexCache}; + let index_url_str = index_url.as_str().to_string(); + let index_cache = ComboIndexCache::new(tame_index::IndexLocation::new(index_url)) .context("failed to open crates.io index cache")?; @@ -620,6 +639,7 @@ impl RustdocFromRegistry { target_root: target_root.to_owned(), version: None, index, + index_url: index_url_str, }) } @@ -734,7 +754,11 @@ impl RustdocGenerator for RustdocFromRegistry { generation_settings, cache_settings, self.target_root.clone(), - CrateSource::Registry { crate_ }, + CrateSource::Registry { + version: crate_.version.to_string(), + index_url: self.index_url.clone(), + crate_, + }, crate_data, ) } From 89085e7391e59b7dbac27f054fe5080ac5a26e0f Mon Sep 17 00:00:00 2001 From: Andrew Burkett Date: Wed, 25 Sep 2024 11:06:36 -0700 Subject: [PATCH 3/5] Update README with respect to now supported custom registries --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4db288e5..093a7aa1 100644 --- a/README.md +++ b/README.md @@ -123,9 +123,8 @@ The following flags can be used to explicitly specify a baseline instead: The rustdoc json file to use as a semver baseline ``` -Custom registries are not currently supported -([#160](https://github.com/obi1kenobi/cargo-semver-checks/issues/160)), so crates published on -registries other than crates.io should use one of the other approaches of generating the baseline. +For custom registries, use the `--registry` flag with the name of the registry +that you want to use as configured in your `config.toml`. ### What features does `cargo-semver-checks` enable in the tested crates? From 08933bbf296187c6a6db0504c7c811c962e6fdb5 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Wed, 4 Dec 2024 13:39:20 +0800 Subject: [PATCH 4/5] Fixup after rebasing third party registry support on latest `main` --- src/data_generation/generate.rs | 3 +++ src/data_generation/request.rs | 22 +++++++++++++++++++--- src/rustdoc_cmd.rs | 0 src/rustdoc_gen.rs | 9 ++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) delete mode 100644 src/rustdoc_cmd.rs diff --git a/src/data_generation/generate.rs b/src/data_generation/generate.rs index d854eb73..3a13eb2a 100644 --- a/src/data_generation/generate.rs +++ b/src/data_generation/generate.rs @@ -543,6 +543,9 @@ fn create_placeholder_rustdoc_manifest( // Fixes: https://github.com/obi1kenobi/cargo-semver-checks/issues/261 version: Some(format!("={}", request.kind.version()?)), default_features: request.default_features, + registry_index: Some( + request.kind.index_url().map(ToString::to_string)?.clone(), + ), features: request .extra_features .iter() diff --git a/src/data_generation/request.rs b/src/data_generation/request.rs index 1d47d3c9..2b560f7d 100644 --- a/src/data_generation/request.rs +++ b/src/data_generation/request.rs @@ -15,6 +15,8 @@ use super::progress::{CallbackHandler, ProgressCallbacks}; #[derive(Debug, Clone)] pub(super) struct RegistryRequest<'a> { index_entry: &'a tame_index::IndexVersion, + // /// The url of the registry index that holds the specified crate + index_url: String, } #[derive(Debug, Clone)] @@ -31,7 +33,7 @@ pub(super) enum RequestKind<'a> { impl RequestKind<'_> { pub(super) fn name(&self) -> anyhow::Result<&str> { Ok(match self { - Self::Registry(RegistryRequest { index_entry }) => &index_entry.name, + Self::Registry(RegistryRequest { index_entry, .. }) => &index_entry.name, Self::LocalProject(ProjectRequest { manifest }) => { crate::manifest::get_package_name(manifest)? } @@ -40,12 +42,22 @@ impl RequestKind<'_> { pub(super) fn version(&self) -> anyhow::Result<&str> { Ok(match self { - Self::Registry(RegistryRequest { index_entry }) => index_entry.version.as_str(), + Self::Registry(RegistryRequest { index_entry, .. }) => index_entry.version.as_str(), Self::LocalProject(ProjectRequest { manifest }) => { crate::manifest::get_package_version(manifest)? } }) } + + pub(super) fn index_url(&self) -> anyhow::Result<&str> { + Ok(match self { + Self::Registry(RegistryRequest { index_url, .. }) => index_url.as_str(), + Self::LocalProject(ProjectRequest { manifest: _ }) => { + // Unclear what we should do here, panic for now... + todo!() + } + }) + } } #[allow(dead_code)] @@ -213,6 +225,7 @@ pub(crate) struct CrateDataRequest<'a> { impl<'a> CrateDataRequest<'a> { pub(crate) fn from_index( index_entry: &'a tame_index::IndexVersion, + index_url: String, default_features: bool, extra_features: BTreeSet>, build_target: Option<&'a str>, @@ -220,7 +233,10 @@ impl<'a> CrateDataRequest<'a> { ) -> Self { let features_fingerprint = make_features_hash(default_features, &extra_features); Self { - kind: RequestKind::Registry(RegistryRequest { index_entry }), + kind: RequestKind::Registry(RegistryRequest { + index_entry, + index_url, + }), default_features, extra_features, build_target, diff --git a/src/rustdoc_cmd.rs b/src/rustdoc_cmd.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/src/rustdoc_gen.rs b/src/rustdoc_gen.rs index 632c35d7..a407d95d 100644 --- a/src/rustdoc_gen.rs +++ b/src/rustdoc_gen.rs @@ -18,7 +18,6 @@ pub(crate) enum CrateSource<'a> { crate_: &'a tame_index::IndexVersion, /// The url of the registry index that holds the specified crate index_url: String, - version: String, }, ManifestPath { manifest: &'a Manifest, @@ -268,8 +267,11 @@ fn generate_rustdoc( ); let request = match crate_source { - CrateSource::Registry { crate_, .. } => CrateDataRequest::from_index( + CrateSource::Registry { + crate_, index_url, .. + } => CrateDataRequest::from_index( crate_, + index_url, default_features, extra_features, crate_data.build_target, @@ -552,6 +554,8 @@ pub(crate) struct RustdocFromRegistry { version: Option, index: tame_index::index::ComboIndex, /// The url of the index for the given registry + /// + /// TODO unused! index_url: String, } @@ -755,7 +759,6 @@ impl RustdocGenerator for RustdocFromRegistry { cache_settings, self.target_root.clone(), CrateSource::Registry { - version: crate_.version.to_string(), index_url: self.index_url.clone(), crate_, }, From fd93369763ca045ff836b2327a6e0b353d21d736 Mon Sep 17 00:00:00 2001 From: FujiApple Date: Mon, 16 Dec 2024 12:05:26 +0800 Subject: [PATCH 5/5] Add custom registry test - An ephemeral axum http server is started, which serves a static file based Cargo registry (using margo) called custom-registry. - The registry custom-registry is pre-populated with the test_crates/custom_registry/old crate (version 0.1.0). - The test runs semver-checks on test_crates/custom_registry/new (version 0.1.1) against registry custom-registry and asserts that there are no SemVer violations. - After the test the axum server is shutdown gracefully on both success and failure, there is also a timeout ensure the test does not hang. --- Cargo.lock | 293 ++++++++++++++++++ Cargo.toml | 6 + .../custom_registry/new/.cargo/config.toml | 2 + test_crates/custom_registry/new/.gitignore | 2 + test_crates/custom_registry/new/Cargo.toml | 7 + test_crates/custom_registry/new/src/lib.rs | 2 + .../custom_registry/old/.cargo/config.toml | 2 + test_crates/custom_registry/old/.gitignore | 2 + test_crates/custom_registry/old/Cargo.toml | 7 + test_crates/custom_registry/old/src/lib.rs | 1 + .../custom_registry/registry/config.json | 1 + .../crates/cu/st/custom_registry/0.1.0.crate | Bin 0 -> 886 bytes .../registry/cu/st/custom_registry | 1 + .../registry/margo-config.toml | 7 + tests/custom_registry.rs | 67 ++++ 15 files changed, 400 insertions(+) create mode 100644 test_crates/custom_registry/new/.cargo/config.toml create mode 100644 test_crates/custom_registry/new/.gitignore create mode 100644 test_crates/custom_registry/new/Cargo.toml create mode 100644 test_crates/custom_registry/new/src/lib.rs create mode 100644 test_crates/custom_registry/old/.cargo/config.toml create mode 100644 test_crates/custom_registry/old/.gitignore create mode 100644 test_crates/custom_registry/old/Cargo.toml create mode 100644 test_crates/custom_registry/old/src/lib.rs create mode 100644 test_crates/custom_registry/registry/config.json create mode 100644 test_crates/custom_registry/registry/crates/cu/st/custom_registry/0.1.0.crate create mode 100644 test_crates/custom_registry/registry/cu/st/custom_registry create mode 100644 test_crates/custom_registry/registry/margo-config.toml create mode 100644 tests/custom_registry.rs diff --git a/Cargo.lock b/Cargo.lock index 269c1f62..5d2a8683 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,6 +164,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "async-trait" +version = "0.1.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -187,6 +198,61 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "backtrace" version = "0.3.74" @@ -335,6 +401,7 @@ dependencies = [ "anyhow", "assert_cmd", "atty", + "axum", "bugreport", "cargo-config2", "cargo_metadata 0.19.1", @@ -355,6 +422,7 @@ dependencies = [ "predicates", "rayon", "regex", + "reqwest", "ron 0.8.1", "rustc_version", "semver", @@ -363,7 +431,11 @@ dependencies = [ "sha2", "similar-asserts", "tame-index", + "tokio", + "tokio-util", "toml 0.8.19", + "tower", + "tower-http", "trustfall", "trustfall_core", "trustfall_rustdoc", @@ -781,6 +853,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -1750,12 +1837,24 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" + [[package]] name = "httparse" version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + [[package]] name = "human-panic" version = "2.0.2" @@ -1785,6 +1884,7 @@ dependencies = [ "http", "http-body", "httparse", + "httpdate", "itoa", "pin-project-lite", "smallvec", @@ -1810,6 +1910,22 @@ dependencies = [ "webpki-roots", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.10" @@ -2168,6 +2284,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +[[package]] +name = "matchit" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" + [[package]] name = "maybe-async" version = "0.2.10" @@ -2200,6 +2322,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "miniz_oxide" version = "0.8.0" @@ -2220,6 +2352,23 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -2265,6 +2414,32 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "openssl" +version = "0.10.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -2629,11 +2804,13 @@ dependencies = [ "http-body-util", "hyper", "hyper-rustls", + "hyper-tls", "hyper-util", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", @@ -2647,6 +2824,7 @@ dependencies = [ "sync_wrapper", "system-configuration", "tokio", + "tokio-native-tls", "tokio-rustls", "tokio-util", "tower-service", @@ -2818,6 +2996,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + [[package]] name = "ryu" version = "1.0.18" @@ -2848,6 +3032,29 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.6.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.24" @@ -2889,6 +3096,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +dependencies = [ + "itoa", + "serde", +] + [[package]] name = "serde_spanned" version = "0.6.8" @@ -3217,9 +3434,31 @@ dependencies = [ "mio", "pin-project-lite", "socket2", + "tokio-macros", "windows-sys 0.52.0", ] +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.26.1" @@ -3295,6 +3534,53 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403fa3b783d4b626a8ad51d766ab03cb6d2dbfc46b1c5d4448395e6628dc9697" +dependencies = [ + "bitflags 2.6.0", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "http-range-header", + "httpdate", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + [[package]] name = "tower-service" version = "0.3.3" @@ -3307,6 +3593,7 @@ version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ + "log", "pin-project-lite", "tracing-core", ] @@ -3481,6 +3768,12 @@ dependencies = [ "arrayvec", ] +[[package]] +name = "unicase" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e51b68083f157f853b6379db119d1c1be0e6e4dec98101079dec41f6f5cf6df" + [[package]] name = "unicode-bom" version = "2.0.3" diff --git a/Cargo.toml b/Cargo.toml index b4ee7091..d2152418 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,12 @@ regex = "1.11.1" insta-cmd = "0.6.0" rayon = "1.10.0" trustfall_core = "0.8.0" # Ensure this matches the `trustfall` version above. +axum = "0.7.9" +tokio = "1.42.0" +tokio-util = "0.7.13" +tower = "0.5.1" +tower-http = { version = "0.6.1", features = ["fs", "timeout"] } +reqwest = "0.12.9" # In dev and test profiles, compile all dependencies with optimizations enabled, # but still checking debug assertions and overflows. diff --git a/test_crates/custom_registry/new/.cargo/config.toml b/test_crates/custom_registry/new/.cargo/config.toml new file mode 100644 index 00000000..8fef7e38 --- /dev/null +++ b/test_crates/custom_registry/new/.cargo/config.toml @@ -0,0 +1,2 @@ +[registries] +custom-registry = { index = "sparse+http://127.0.0.1:5000/" } \ No newline at end of file diff --git a/test_crates/custom_registry/new/.gitignore b/test_crates/custom_registry/new/.gitignore new file mode 100644 index 00000000..73e042d0 --- /dev/null +++ b/test_crates/custom_registry/new/.gitignore @@ -0,0 +1,2 @@ +# needed for this test +!.cargo/config.toml \ No newline at end of file diff --git a/test_crates/custom_registry/new/Cargo.toml b/test_crates/custom_registry/new/Cargo.toml new file mode 100644 index 00000000..42198723 --- /dev/null +++ b/test_crates/custom_registry/new/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "custom_registry" +version = "0.1.1" +edition = "2021" + +[dependencies] diff --git a/test_crates/custom_registry/new/src/lib.rs b/test_crates/custom_registry/new/src/lib.rs new file mode 100644 index 00000000..c7a1d1c1 --- /dev/null +++ b/test_crates/custom_registry/new/src/lib.rs @@ -0,0 +1,2 @@ +pub struct Dummy; +pub struct DummyNew; \ No newline at end of file diff --git a/test_crates/custom_registry/old/.cargo/config.toml b/test_crates/custom_registry/old/.cargo/config.toml new file mode 100644 index 00000000..8fef7e38 --- /dev/null +++ b/test_crates/custom_registry/old/.cargo/config.toml @@ -0,0 +1,2 @@ +[registries] +custom-registry = { index = "sparse+http://127.0.0.1:5000/" } \ No newline at end of file diff --git a/test_crates/custom_registry/old/.gitignore b/test_crates/custom_registry/old/.gitignore new file mode 100644 index 00000000..73e042d0 --- /dev/null +++ b/test_crates/custom_registry/old/.gitignore @@ -0,0 +1,2 @@ +# needed for this test +!.cargo/config.toml \ No newline at end of file diff --git a/test_crates/custom_registry/old/Cargo.toml b/test_crates/custom_registry/old/Cargo.toml new file mode 100644 index 00000000..e27c523e --- /dev/null +++ b/test_crates/custom_registry/old/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "custom_registry" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/custom_registry/old/src/lib.rs b/test_crates/custom_registry/old/src/lib.rs new file mode 100644 index 00000000..4c941411 --- /dev/null +++ b/test_crates/custom_registry/old/src/lib.rs @@ -0,0 +1 @@ +pub struct Dummy; \ No newline at end of file diff --git a/test_crates/custom_registry/registry/config.json b/test_crates/custom_registry/registry/config.json new file mode 100644 index 00000000..65ebcb7a --- /dev/null +++ b/test_crates/custom_registry/registry/config.json @@ -0,0 +1 @@ +{"dl":"http://127.0.0.1:5000/crates/{lowerprefix}/{crate}/{version}.crate","api":null,"auth-required":false} \ No newline at end of file diff --git a/test_crates/custom_registry/registry/crates/cu/st/custom_registry/0.1.0.crate b/test_crates/custom_registry/registry/crates/cu/st/custom_registry/0.1.0.crate new file mode 100644 index 0000000000000000000000000000000000000000..7e2de995d86fab15a6fdb34268bbb2a98c8e668a GIT binary patch literal 886 zcmV-+1Bv_}iwFn+00002|6_G?bZ>26a%E>}b98cfEif)IE-)@*a$$630PR>&Z__Xk z?sI;{k-dNzX_B_-HpD|2V@w(#u^}`~({P+iV&=q^A4v^3xB3uoL+G zDDXo+?AiVx>J5XA-&q03ex?C#Eoa%dHNol3^8%|ghd06S=vy$r6Zj0GOz?`{+-l5p zg%5LM#yj0^5Dq<`e!!!GFU4^N+kb7iFrv50xr!&;K7##t*}JE+Fn( z{`bQuS}*>uDLy*@ZYGSo1NM~~Rn7uxxr3gMy(r?zFhNYW!Z_gr&bGIiKj`(M6t|)z z^yBTs-JH%#gf)f~KShMd zN~Q5G*7#NZ_XpqA|A9Yf>;EdS0VQIB38YGc$wdX0qt3m%Jpr~@FaGaZ=iiyve^LK~ zUO!r{|6w?6>;G!_fBfR$2%aAt?g2eVZ;xNU933C*jt&n`V1Mt`-kZ_!-ZOZ50=uI( z`>&l1X9M2lSVBFPiY21VU|P??D9RrQ*O!MThTu|239P12Vn%Q#<%9&dR9Olp#V2%O z9%_&ZNpfr=D%h2v0l-y3CkPP>DU6+XDNGI|1U{m!geogg>1-iZCiJCJq`;*X2I0Lu zd%TAP$4FP0lG6=`Bp5Z<@IHE(w>i__6Y9Z@!CqtQK?)O91Jl;Bsl82>w7No!z%K14 zlQYv;ue8WSNt(~iYSbo`rMN&j0jbo5Reu7BNK@2U8n|zjFKV7cp{5Jbd7H%&ACMAo zgt#EivrEjf^}>3Ts11oCt)0^`;}#|G>y)fO+gf71>&*7kerqy- z>%_H?3AIz&RCLC5EJc-Hx2;E|h;OuGLH=0mz$;datxFd>ZF#xb6Vra@3#05lH)>9s z&M7T)_G8tpo16Qo=3N@;>B^-!i=I4l+C2ZK`M(LbzkL1+DE}{?|AvEpd;VL+|3BBs zVwvKb%7 literal 0 HcmV?d00001 diff --git a/test_crates/custom_registry/registry/cu/st/custom_registry b/test_crates/custom_registry/registry/cu/st/custom_registry new file mode 100644 index 00000000..173f24dc --- /dev/null +++ b/test_crates/custom_registry/registry/cu/st/custom_registry @@ -0,0 +1 @@ +{"name":"custom_registry","vers":"0.1.0","deps":[],"cksum":"d0ad6b64ea3140e5d859432285042abe32bf3ec332b0d7d8869074bc9c159d7f","features":{},"yanked":false,"v":2} diff --git a/test_crates/custom_registry/registry/margo-config.toml b/test_crates/custom_registry/registry/margo-config.toml new file mode 100644 index 00000000..90e46b88 --- /dev/null +++ b/test_crates/custom_registry/registry/margo-config.toml @@ -0,0 +1,7 @@ +version = "1" +base_url = "http://127.0.0.1:5000/" +auth_required = false + +[html] +enabled = false +suggested_registry_name = "custom-registry" diff --git a/tests/custom_registry.rs b/tests/custom_registry.rs new file mode 100644 index 00000000..7e6571d3 --- /dev/null +++ b/tests/custom_registry.rs @@ -0,0 +1,67 @@ +use assert_cmd::Command; +use axum::Router; +use std::net::SocketAddr; +use std::str::FromStr; +use std::time::Duration; +use tokio_util::sync::CancellationToken; +use tower_http::services::ServeDir; +use tower_http::timeout::TimeoutLayer; + +const HOST: &str = "127.0.0.1"; +const PORT: u16 = 5000; + +#[tokio::test] +async fn test_custom_registry() { + let token = CancellationToken::new(); + let cloned_token = token.clone(); + tokio::join!( + async { + tokio::time::timeout(Duration::from_secs(10), async { + while reqwest::get(format!("http://{HOST}:{PORT}")).await.is_err() { + tokio::time::sleep(Duration::from_millis(100)).await; + } + tokio::task::spawn_blocking(move || verify_custom_registry(token)) + .await + .expect("registry failure"); + }) + .await + .expect("timeout failure"); + }, + serve(using_serve_dir(), cloned_token) + ); +} + +async fn serve(app: Router, token: CancellationToken) { + let addr = SocketAddr::from_str(&format!("{HOST}:{PORT}")).expect("Failed to parse HOST:PORT"); + let listener = tokio::net::TcpListener::bind(addr) + .await + .expect("failed to bind"); + axum::serve( + listener, + app.layer(TimeoutLayer::new(Duration::from_secs(10))), + ) + .with_graceful_shutdown(shutdown_signal(token)) + .await + .expect("failed to serve"); +} + +fn using_serve_dir() -> Router { + Router::new().nest_service("/", ServeDir::new("test_crates/custom_registry/registry")) +} + +fn verify_custom_registry(token: CancellationToken) { + let mut cmd = + Command::cargo_bin("cargo-semver-checks").expect("failed to execute cargo-semver-checks"); + let result = cmd + .current_dir("test_crates/custom_registry/new") + .args(["semver-checks", "--registry", "custom-registry"]) + .assert(); + token.cancel(); + result.success(); +} + +async fn shutdown_signal(token: CancellationToken) { + tokio::select! { + _ = token.cancelled() => {} + } +}