Skip to content

Commit

Permalink
replace optional_features with extras
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Jan 22, 2025
1 parent 0fa69ea commit ef77099
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 133 deletions.
89 changes: 2 additions & 87 deletions .github/workflows/rust-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,97 +146,12 @@ jobs:
run: >
cargo nextest run
--workspace
--features ${{ env.DEFAULT_FEATURES }}
--features ${{ env.DEFAULT_FEATURES }} extras
--target ${{ matrix.target }}
${{ steps.build-options.outputs.CARGO_BUILD_OPTIONS}}
${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}
- name: Run doctests
if: ${{ !matrix.skip-tests }}
run: >
cargo test --doc
test-experimental:
name: Test Experimental Features (${{ matrix.name }})
runs-on: ${{ matrix.os }}
needs: [ format_and_lint ]
strategy:
fail-fast: false
matrix:
include:
- { name: "Linux-x86_64", target: x86_64-unknown-linux-musl, os: ubuntu-22.04 }
- { name: "Linux-aarch64", target: aarch64-unknown-linux-musl, os: ubuntu-latest, skip-tests: true }
- { name: "Linux-arm", target: arm-unknown-linux-musleabi, os: ubuntu-latest, use-cross: true, skip-tests: true }

# - { name: "Linux-mips", target: mips-unknown-linux-musl, os: ubuntu-latest, use-cross: true, skip-tests: true }
# - { name: "Linux-mipsel", target: mipsel-unknown-linux-musl, os: ubuntu-latest, use-cross: true, skip-tests: true }
# - { name: "Linux-mips64", target: mips64-unknown-linux-muslabi64, os: ubuntu-latest, use-cross: true, skip-tests: true }
# - { name: "Linux-mips64el", target: mips64el-unknown-linux-muslabi64, os: ubuntu-latest, use-cross: true, skip-tests: true }

# - { name: "Linux-powerpc", target: powerpc-unknown-linux-gnu, os: ubuntu-latest, use-cross: true, skip-tests: true }
- { name: "Linux-powerpc64", target: powerpc64-unknown-linux-gnu, os: ubuntu-latest, use-cross: true, skip-tests: true }
- { name: "Linux-powerpc64le", target: powerpc64le-unknown-linux-gnu, os: ubuntu-latest, use-cross: true, skip-tests: true }

- { name: "Linux-s390x", target: s390x-unknown-linux-gnu, os: ubuntu-latest, use-cross: true, skip-tests: true }

- { name: "macOS-x86_64", target: x86_64-apple-darwin, os: macOS-latest }
- { name: "macOS-aarch64", target: aarch64-apple-darwin, os: macOS-latest, skip-tests: true }

- { name: "Windows-x86_64", target: x86_64-pc-windows-msvc, os: windows-latest }
- { name: "Windows-aarch64", target: aarch64-pc-windows-msvc, os: windows-latest, skip-tests: true }
feature-set:
- "optional_features"

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
components: rustfmt
cache: false

- uses: taiki-e/setup-cross-toolchain-action@v1
if: matrix.target != 'x86_64-unknown-linux-musl'
with:
target: ${{ matrix.target }}

- if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt install musl-tools gcc g++
sudo ln -s /usr/bin/musl-gcc /usr/bin/musl-g++
- uses: Swatinem/rust-cache@v2

- name: Install cargo nextest
if: ${{ !matrix.skip-tests }}
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest

- name: Use rustls on musl targets.
id: build-options
if: contains(matrix.target, '-musl') || startsWith(matrix.target, 'powerpc') || startsWith(matrix.target, 's390x')
run: |
echo "CARGO_BUILD_OPTIONS=${CARGO_BUILD_OPTIONS} --no-default-features --features rustls-tls" >> $GITHUB_OUTPUT
- name: Run feature-specific tests
if: ${{ !matrix.skip-tests }}
run: >
cargo nextest run
--workspace
--features ${{ matrix.feature-set }}
--target ${{ matrix.target }}
${{ steps.build-options.outputs.CARGO_BUILD_OPTIONS}}
"optional_"
- name: Run feature-specific doctests
if: ${{ !matrix.skip-tests }}
run: >
cargo test --doc
--features ${{ matrix.feature-set }}
--target ${{ matrix.target }}
${{ steps.build-options.outputs.CARGO_BUILD_OPTIONS}}
cargo test --doc
2 changes: 1 addition & 1 deletion crates/rattler_conda_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme.workspace = true

[features]
default = ["rayon"]
optional_features = []
extras = []

[dependencies]
chrono = { workspace = true }
Expand Down
12 changes: 6 additions & 6 deletions crates/rattler_conda_types/src/match_spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub struct MatchSpec {
/// Match the specific filename of the package
pub file_name: Option<String>,
/// The selected optional features of the package
pub optional_features: Option<Vec<String>>,
pub extras: Option<Vec<String>>,
/// The channel of the package
pub channel: Option<Arc<Channel>>,
/// The subdir of the channel
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Display for MatchSpec {
None => write!(f, "*")?,
}

match &self.optional_features {
match &self.extras {
Some(dependencies) => {
write!(f, "[")?;
write!(f, "{}", dependencies.iter().format(", "))?;
Expand Down Expand Up @@ -233,7 +233,7 @@ impl MatchSpec {
build: self.build,
build_number: self.build_number,
file_name: self.file_name,
optional_features: self.optional_features,
extras: self.extras,
channel: self.channel,
subdir: self.subdir,
namespace: self.namespace,
Expand Down Expand Up @@ -279,7 +279,7 @@ pub struct NamelessMatchSpec {
/// Match the specific filename of the package
pub file_name: Option<String>,
/// The selected optional features of the package
pub optional_features: Option<Vec<String>>,
pub extras: Option<Vec<String>>,
/// The channel of the package
#[serde(deserialize_with = "deserialize_channel", default)]
pub channel: Option<Arc<Channel>>,
Expand Down Expand Up @@ -333,7 +333,7 @@ impl From<MatchSpec> for NamelessMatchSpec {
build: spec.build,
build_number: spec.build_number,
file_name: spec.file_name,
optional_features: spec.optional_features,
extras: spec.extras,
channel: spec.channel,
subdir: spec.subdir,
namespace: spec.namespace,
Expand All @@ -353,7 +353,7 @@ impl MatchSpec {
build: spec.build,
build_number: spec.build_number,
file_name: spec.file_name,
optional_features: spec.optional_features,
extras: spec.extras,
channel: spec.channel,
subdir: spec.subdir,
namespace: spec.namespace,
Expand Down
16 changes: 8 additions & 8 deletions crates/rattler_conda_types/src/match_spec/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ fn strip_brackets(input: &str) -> Result<(Cow<'_, str>, BracketVec<'_>), ParseMa
}
}

#[cfg(feature = "optional_features")]
#[cfg(feature = "extras")]
/// Parses a list of optional dependencies from a string `[feat1, feat2, feat3]`.
pub fn parse_optional_features(input: &str) -> Result<Vec<String>, ParseMatchSpecError> {
pub fn parse_extras(input: &str) -> Result<Vec<String>, ParseMatchSpecError> {
use nom::combinator::map;

fn parse_features(input: &str) -> IResult<&str, Vec<String>> {
Expand Down Expand Up @@ -272,16 +272,16 @@ fn parse_bracket_vec_into_components(
"version" => match_spec.version = Some(VersionSpec::from_str(value, strictness)?),
"build" => match_spec.build = Some(StringMatcher::from_str(value)?),
"build_number" => match_spec.build_number = Some(BuildNumberSpec::from_str(value)?),
"optional_features" => {
"extras" => {
// Optional features are still experimental
#[cfg(feature = "optional_features")]
#[cfg(feature = "extras")]
{
match_spec.optional_features = Some(parse_optional_features(value)?);
match_spec.extras = Some(parse_extras(value)?);
}
#[cfg(not(feature = "optional_features"))]
#[cfg(not(feature = "extras"))]
{
return Err(ParseMatchSpecError::InvalidBracketKey(
"optional_features".to_string(),
"extras".to_string(),
));
}
}
Expand Down Expand Up @@ -1379,7 +1379,7 @@ mod tests {
build: "py27_0*".parse().ok(),
build_number: Some(BuildNumberSpec::from_str(">=6").unwrap()),
file_name: Some("foo-1.0-py27_0.tar.bz2".to_string()),
optional_features: None,
extras: None,
channel: Some(
Channel::from_str("conda-forge", &channel_config())
.map(Arc::new)
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler_solve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ url = { workspace = true }
default = ["resolvo"]
libsolv_c = ["rattler_libsolv_c", "libc"]
resolvo = ["dep:resolvo", "dep:futures"]
optional_features = []
extras = []

[[bench]]
name = "bench"
Expand Down
6 changes: 3 additions & 3 deletions crates/rattler_solve/src/resolvo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl<'a> DependencyProvider for CondaDependencyProvider<'a> {
subdir: Some(record.package_record.subdir.clone()),
md5: record.package_record.md5,
sha256: record.package_record.sha256,
optional_features: None,
extras: None,
..Default::default()
};

Expand Down Expand Up @@ -841,7 +841,7 @@ impl super::SolverImpl for Solver {

let root_requirements = task.specs.iter().flat_map(|spec| {
let (name, nameless_spec) = spec.clone().into_nameless();
let features = &spec.optional_features;
let features = &spec.extras;
let name = name.expect("cannot use matchspec without a name");
let name_id = provider.pool.intern_package_name(name.as_normalized());
let mut reqs = vec![provider
Expand Down Expand Up @@ -940,7 +940,7 @@ fn parse_match_spec(
let (name, spec) = match_spec.into_nameless();

let mut version_set_ids = vec![];
if let Some(ref features) = spec.optional_features {
if let Some(ref features) = spec.extras {
let spec_with_feature: SolverMatchSpec<'_> = spec.clone().into();

for feature in features {
Expand Down
Loading

0 comments on commit ef77099

Please sign in to comment.