Skip to content

Commit

Permalink
feat: allow declaring [executable] target
Browse files Browse the repository at this point in the history
commit-id:12d49314
  • Loading branch information
FroyaTheHen committed Jan 8, 2025
1 parent e18c4ef commit 3f94464
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions scarb/src/core/manifest/toml_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct TomlManifest {
pub dependencies: Option<BTreeMap<PackageName, MaybeTomlWorkspaceDependency>>,
pub dev_dependencies: Option<BTreeMap<PackageName, MaybeTomlWorkspaceDependency>>,
pub lib: Option<TomlTarget<TomlLibTargetParams>>,
pub executable: Option<TomlTarget<TomlExecutableTargetParams>>,
pub cairo_plugin: Option<TomlTarget<TomlCairoPluginTargetParams>>,
pub test: Option<Vec<TomlTarget<TomlExternalTargetParams>>>,
pub target: Option<BTreeMap<TargetKind, Vec<TomlTarget<TomlExternalTargetParams>>>>,
Expand Down Expand Up @@ -295,6 +296,10 @@ pub struct TomlLibTargetParams {
pub sierra_text: Option<bool>,
}

#[derive(Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct TomlExecutableTargetParams {}

#[derive(Debug, Default, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct TomlCairoPluginTargetParams {
Expand Down Expand Up @@ -640,6 +645,14 @@ impl TomlManifest {
None,
)?);

targets.extend(Self::collect_target(
TargetKind::EXECUTABLE,
self.executable.as_ref(),
&package_name,
root,
None,
)?);

for (kind, ext_toml) in self
.target
.iter()
Expand Down
1 change: 1 addition & 0 deletions scarb/src/core/publishing/manifest_normalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn prepare_manifest_for_publish(pkg: &Package) -> Result<TomlManifest> {
dependencies,
dev_dependencies: None,
lib: None,
executable: None,
cairo_plugin,
test: None,
target: None,
Expand Down
29 changes: 29 additions & 0 deletions scarb/tests/build_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,3 +1119,32 @@ fn test_executable_compiler_creates_output_files() {
t.child("target/dev/executable_test.executable.json")
.assert(predicates::path::exists());
}

#[test]
fn compile_executable_target_can_use_short_declaration() {
let t = TempDir::new().unwrap();
ProjectBuilder::start()
.name("executable_test")
.dep_cairo_test()
.dep_starknet()
.dep_cairo_execute()
.manifest_extra(indoc! {r#"
[executable]
"#})
.lib_cairo(indoc! {r#"
#[executable]
fn main() -> felt252 {
42
}
"#})
.build(&t);

Scarb::quick_snapbox()
.arg("build")
.current_dir(&t)
.assert()
.success();

t.child("target/dev/executable_test.executable.json")
.assert(predicates::path::exists());
}

0 comments on commit 3f94464

Please sign in to comment.