Skip to content

Commit

Permalink
Add --ignore-cairo-version flag (#1666)
Browse files Browse the repository at this point in the history
Closes #1661
  • Loading branch information
DelevoXDG authored Nov 5, 2024
1 parent dd56c33 commit 9b313d6
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 45 deletions.
20 changes: 20 additions & 0 deletions scarb/src/bin/scarb/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ pub struct BuildArgs {
/// Specify features to enable.
#[command(flatten)]
pub features: FeaturesSpec,

/// Do not error on `cairo-version` mismatch.
#[arg(long)]
pub ignore_cairo_version: bool,
}

/// Arguments accepted by the `expand` command.
Expand All @@ -245,6 +249,10 @@ pub struct ExpandArgs {
#[command(flatten)]
pub features: FeaturesSpec,

/// Do not error on `cairo-version` mismatch.
#[arg(long)]
pub ignore_cairo_version: bool,

/// Specify the target to expand by target kind.
#[arg(long)]
pub target_kind: Option<String>,
Expand Down Expand Up @@ -316,6 +324,10 @@ pub struct MetadataArgs {
/// Specify features to enable.
#[command(flatten)]
pub features: FeaturesSpec,

/// Do not error on `cairo-version` mismatch.
#[arg(long)]
pub ignore_cairo_version: bool,
}

/// Arguments accepted by the `new` command.
Expand Down Expand Up @@ -489,6 +501,10 @@ pub struct PackageArgs {
/// Specify features to enable.
#[command(flatten)]
pub features: FeaturesSpec,

/// Do not error on `cairo-version` mismatch.
#[arg(long)]
pub ignore_cairo_version: bool,
}

/// Arguments accepted by the `publish` command.
Expand All @@ -507,6 +523,10 @@ pub struct PublishArgs {
/// Specify features to enable.
#[command(flatten)]
pub features: FeaturesSpec,

/// Do not error on `cairo-version` mismatch.
#[arg(long)]
pub ignore_cairo_version: bool,
}

/// Git reference specification arguments.
Expand Down
1 change: 1 addition & 0 deletions scarb/src/bin/scarb/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn run(args: BuildArgs, config: &Config) -> Result<()> {
.collect::<Vec<_>>();
let opts = CompileOpts::try_new(
args.features,
args.ignore_cairo_version,
args.test,
args.target_names,
args.target_kinds,
Expand Down
1 change: 1 addition & 0 deletions scarb/src/bin/scarb/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn run(args: BuildArgs, config: &Config) -> Result<()> {
.collect::<Vec<_>>();
let opts = CompileOpts::try_new(
args.features,
args.ignore_cairo_version,
args.test,
args.target_names,
args.target_kinds,
Expand Down
1 change: 1 addition & 0 deletions scarb/src/bin/scarb/commands/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn run(args: ExpandArgs, config: &Config) -> Result<()> {
let package = args.packages_filter.match_one(&ws)?;
let opts = ExpandOpts {
features: args.features.try_into()?,
ignore_cairo_version: args.ignore_cairo_version,
ugly: args.ugly,
target_name: args.target_name.map(|n| n.to_smolstr()),
target_kind: args.target_kind.map(TargetKind::try_new).transpose()?,
Expand Down
1 change: 1 addition & 0 deletions scarb/src/bin/scarb/commands/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn run(args: MetadataArgs, config: &Config) -> Result<()> {
version: args.format_version,
no_deps: args.no_deps,
features,
ignore_cairo_version: args.ignore_cairo_version,
};

let metadata = ops::collect_metadata(&opts, &ws)?;
Expand Down
1 change: 1 addition & 0 deletions scarb/src/bin/scarb/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn run(args: PackageArgs, config: &Config) -> Result<()> {
verify: !args.shared_args.no_verify,
check_metadata: !args.no_metadata,
features: features_opts,
ignore_cairo_version: args.ignore_cairo_version,
};

let packages = packages.into_iter().map(|p| p.id).collect_vec();
Expand Down
1 change: 1 addition & 0 deletions scarb/src/bin/scarb/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn run(args: PublishArgs, config: &Config) -> Result<()> {
verify: !args.shared_args.no_verify,
check_metadata: true,
features: features_opts,
ignore_cairo_version: args.ignore_cairo_version,
},
};

Expand Down
60 changes: 32 additions & 28 deletions scarb/src/ops/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ pub struct CompileOpts {
pub exclude_target_kinds: Vec<TargetKind>,
pub include_target_names: Vec<SmolStr>,
pub features: FeaturesOpts,
pub ignore_cairo_version: bool,
}

impl CompileOpts {
pub fn try_new(
features: FeaturesSpec,
ignore_cairo_version: bool,
test: bool,
target_names: Vec<String>,
target_kinds: Vec<String>,
Expand All @@ -88,6 +90,7 @@ impl CompileOpts {
.map(|v| v.to_smolstr())
.collect_vec(),
features: features.try_into()?,
ignore_cairo_version,
})
}
}
Expand Down Expand Up @@ -121,35 +124,36 @@ where
validate_features(&packages_to_process, &opts.features)?;
// Add test compilation units to build
let packages = get_test_package_ids(packages, ws);
let compilation_units = ops::generate_compilation_units(&resolve, &opts.features, ws)?
.into_iter()
.filter(|cu| {
let is_excluded = opts
.exclude_target_kinds
.contains(&cu.main_component().target_kind());
let is_included = opts.include_target_kinds.is_empty()
|| opts
.include_target_kinds
let compilation_units =
ops::generate_compilation_units(&resolve, &opts.features, opts.ignore_cairo_version, ws)?
.into_iter()
.filter(|cu| {
let is_excluded = opts
.exclude_target_kinds
.contains(&cu.main_component().target_kind());
let is_included = is_included
&& (opts.include_target_names.is_empty()
|| cu
.main_component()
.targets
.iter()
.any(|t| opts.include_target_names.contains(&t.name)));
let is_selected = packages.contains(&cu.main_package_id());
let is_cairo_plugin = matches!(cu, CompilationUnit::ProcMacro(_));
is_cairo_plugin || (is_selected && is_included && !is_excluded)
})
.sorted_by_key(|cu| {
if matches!(cu, CompilationUnit::ProcMacro(_)) {
0
} else {
1
}
})
.collect::<Vec<_>>();
let is_included = opts.include_target_kinds.is_empty()
|| opts
.include_target_kinds
.contains(&cu.main_component().target_kind());
let is_included = is_included
&& (opts.include_target_names.is_empty()
|| cu
.main_component()
.targets
.iter()
.any(|t| opts.include_target_names.contains(&t.name)));
let is_selected = packages.contains(&cu.main_package_id());
let is_cairo_plugin = matches!(cu, CompilationUnit::ProcMacro(_));
is_cairo_plugin || (is_selected && is_included && !is_excluded)
})
.sorted_by_key(|cu| {
if matches!(cu, CompilationUnit::ProcMacro(_)) {
0
} else {
1
}
})
.collect::<Vec<_>>();

for unit in compilation_units {
operation(unit, ws)?;
Expand Down
4 changes: 3 additions & 1 deletion scarb/src/ops/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum ExpandEmitTarget {
#[derive(Clone, Debug)]
pub struct ExpandOpts {
pub features: FeaturesOpts,
pub ignore_cairo_version: bool,
pub target_kind: Option<TargetKind>,
pub target_name: Option<SmolStr>,
pub ugly: bool,
Expand All @@ -42,7 +43,8 @@ pub fn expand(package: Package, opts: ExpandOpts, ws: &Workspace<'_>) -> Result<

let package_name = package.id.name.to_string();
let resolve = ops::resolve_workspace(ws)?;
let compilation_units = ops::generate_compilation_units(&resolve, &opts.features, ws)?;
let compilation_units =
ops::generate_compilation_units(&resolve, &opts.features, opts.ignore_cairo_version, ws)?;

// Compile procedural macros.
compilation_units
Expand Down
15 changes: 10 additions & 5 deletions scarb/src/ops/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct MetadataOptions {
pub version: u64,
pub no_deps: bool,
pub features: ops::FeaturesOpts,
pub ignore_cairo_version: bool,
}

#[tracing::instrument(skip_all, level = "debug")]
Expand All @@ -43,11 +44,15 @@ pub fn collect_metadata(opts: &MetadataOptions, ws: &Workspace<'_>) -> Result<m:
.map(collect_package_metadata)
.collect();

let compilation_units: Vec<m::CompilationUnitMetadata> =
ops::generate_compilation_units(&resolve, &opts.features, ws)?
.iter()
.flat_map(collect_compilation_unit_metadata)
.collect();
let compilation_units: Vec<m::CompilationUnitMetadata> = ops::generate_compilation_units(
&resolve,
&opts.features,
opts.ignore_cairo_version,
ws,
)?
.iter()
.flat_map(collect_compilation_unit_metadata)
.collect();

(packages, compilation_units)
} else {
Expand Down
13 changes: 11 additions & 2 deletions scarb/src/ops/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct PackageOpts {
pub verify: bool,
pub check_metadata: bool,
pub features: ops::FeaturesOpts,
pub ignore_cairo_version: bool,
}

/// A listing of files to include in the archive, without actually building it yet.
Expand Down Expand Up @@ -183,8 +184,14 @@ fn package_one_impl(
let uncompressed_size = tar(pkg_id, recipe, &mut dst, ws)?;

let mut dst = if opts.verify && !pkg.manifest.targets.iter().any(is_builtin) {
run_verify(pkg, dst, ws, opts.features.clone())
.context("failed to verify package tarball")?
run_verify(
pkg,
dst,
ws,
opts.features.clone(),
opts.ignore_cairo_version,
)
.context("failed to verify package tarball")?
} else {
dst
};
Expand Down Expand Up @@ -359,6 +366,7 @@ fn run_verify(
tar: FileLockGuard,
ws: &Workspace<'_>,
features: ops::FeaturesOpts,
ignore_cairo_version: bool,
) -> Result<FileLockGuard> {
ws.config()
.ui()
Expand All @@ -382,6 +390,7 @@ fn run_verify(
exclude_target_kinds: vec![TargetKind::TEST.clone()],
include_target_names: Vec::new(),
features,
ignore_cairo_version,
},
&ws,
)?;
Expand Down
Loading

0 comments on commit 9b313d6

Please sign in to comment.