Skip to content

Commit

Permalink
feat: skip noarch build if --noarch-build-platform != `build_platfo…
Browse files Browse the repository at this point in the history
…rm` (#1192)
  • Loading branch information
hadim authored Nov 14, 2024
1 parent 8c82b8c commit 5e83d19
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ e.g. `tar-bz2:<number>` (from 1 to 9) or `conda:<number>` (from -7 to
Skip packages that already exist in any channel


- `--noarch-build-platform <NOARCH_BUILD_PLATFORM>`

Define a "noarch platform" for which the noarch packages will be built for. The noarch builds will be skipped on the other platforms





Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ requirements:
tests:
- script:
- bibtex-tidy --version
```
```
1 change: 0 additions & 1 deletion scripts/activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ export CARGO_TARGET_X86_64_APPLE_DARWIN_RUSTFLAGS="-C link-arg=-Wl,-rpath,$CONDA
export CARGO_TARGET_AARCH64_APPLE_DARWIN_RUSTFLAGS="-C link-arg=-Wl,-rpath,$CONDA_PREFIX/lib"

export RATTLER_BUILD_PATH="$PIXI_PROJECT_ROOT/target-pixi/release/rattler-build"

30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ pub fn get_tool_config(
.with_zstd_repodata_enabled(args.common.use_zstd)
.with_bz2_repodata_enabled(args.common.use_zstd)
.with_skip_existing(args.skip_existing)
.with_noarch_build_platform(args.noarch_build_platform)
.finish())
}

Expand Down Expand Up @@ -410,6 +411,35 @@ pub async fn run_build_from_args(
Ok(())
}

/// Check if the noarch builds should be skipped because the noarch platform has been set
pub async fn skip_noarch(
mut outputs: Vec<Output>,
tool_configuration: &tool_configuration::Configuration,
) -> miette::Result<Vec<Output>> {
if let Some(noarch_build_platform) = tool_configuration.noarch_build_platform {
outputs.retain(|output| {
// Skip the build if:
// - target_platform is "noarch"
// and
// - build_platform != noarch_build_platform
let should_skip = output.build_configuration.target_platform == Platform::NoArch
&& output.build_configuration.build_platform.platform != noarch_build_platform;

if should_skip {
// The identifier should always be set at this point
tracing::info!(
"Skipping build because noarch_build_platform is set to {} for {}",
noarch_build_platform,
output.identifier()
);
}
!should_skip
});
}

Ok(outputs)
}

/// Runs test.
pub async fn run_test_from_args(
args: TestOpts,
Expand Down
7 changes: 5 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use rattler_build::{
console_utils::init_logging,
get_build_output, get_recipe_path, get_tool_config,
opt::{App, ShellCompletion, SubCommands},
rebuild_from_args, run_build_from_args, run_test_from_args, sort_build_outputs_topologically,
upload_from_args,
rebuild_from_args, run_build_from_args, run_test_from_args, skip_noarch,
sort_build_outputs_topologically, upload_from_args,
};
use tempfile::tempdir;

Expand Down Expand Up @@ -133,6 +133,9 @@ async fn main() -> miette::Result<()> {
return Ok(());
}

// Skip noarch builds before the topological sort
outputs = skip_noarch(outputs, &tool_config).await?;

sort_build_outputs_topologically(&mut outputs, build_args.up_to.as_deref())?;
run_build_from_args(outputs, tool_config).await?;
}
Expand Down
5 changes: 5 additions & 0 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ pub struct BuildOpts {
)]
pub skip_existing: SkipExisting,

/// Define a "noarch platform" for which the noarch packages will be built
/// for. The noarch builds will be skipped on the other platforms.
#[arg(long, default_value = None, help_heading = "Modifying result")]
pub noarch_build_platform: Option<Platform>,

/// Extra metadata to include in about.json
#[arg(long, value_parser = parse_key_val)]
pub extra_meta: Option<Vec<(String, Value)>>,
Expand Down
16 changes: 15 additions & 1 deletion src/tool_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{path::PathBuf, sync::Arc};

use clap::ValueEnum;
use rattler::package_cache::PackageCache;
use rattler_conda_types::ChannelConfig;
use rattler_conda_types::{ChannelConfig, Platform};
use rattler_networking::{
authentication_storage::{self, backends::file::FileStorageError},
AuthenticationMiddleware, AuthenticationStorage,
Expand Down Expand Up @@ -54,6 +54,9 @@ pub struct Configuration {
/// Whether to skip existing packages
pub skip_existing: SkipExisting,

/// The noarch platform to use (noarch builds are skipped on other platforms)
pub noarch_build_platform: Option<Platform>,

/// The channel configuration to use when parsing channels.
pub channel_config: ChannelConfig,

Expand Down Expand Up @@ -115,6 +118,7 @@ pub struct ConfigurationBuilder {
use_zstd: bool,
use_bz2: bool,
skip_existing: SkipExisting,
noarch_build_platform: Option<Platform>,
channel_config: Option<ChannelConfig>,
compression_threads: Option<u32>,
}
Expand All @@ -138,6 +142,7 @@ impl ConfigurationBuilder {
use_zstd: true,
use_bz2: false,
skip_existing: SkipExisting::None,
noarch_build_platform: None,
channel_config: None,
compression_threads: None,
}
Expand Down Expand Up @@ -232,6 +237,14 @@ impl ConfigurationBuilder {
}
}

/// Define the noarch platform
pub fn with_noarch_build_platform(self, noarch_build_platform: Option<Platform>) -> Self {
Self {
noarch_build_platform,
..self
}
}

/// Construct a [`Configuration`] from the builder.
pub fn finish(self) -> Configuration {
let cache_dir = self.cache_dir.unwrap_or_else(|| {
Expand Down Expand Up @@ -269,6 +282,7 @@ impl ConfigurationBuilder {
use_zstd: self.use_zstd,
use_bz2: self.use_bz2,
skip_existing: self.skip_existing,
noarch_build_platform: self.noarch_build_platform,
channel_config,
compression_threads: self.compression_threads,
package_cache,
Expand Down
2 changes: 1 addition & 1 deletion test-data/recipes/pin_subpackage/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ outputs:
noarch: generic
requirements:
run:
- ${{ pin_subpackage(name, exact=true) }}
- ${{ pin_subpackage(name, exact=true) }}

0 comments on commit 5e83d19

Please sign in to comment.