Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow declaring executable target as [executable] #1852

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -634,6 +639,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());
}
Loading