-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support set backend in mod.json
- Loading branch information
1 parent
5a38a2f
commit 6abe2d9
Showing
17 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
crates/moon/tests/test_cases/backend_in_mod_json.in/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## MoonBit Unicode | ||
|
||
We can use emoji in MoonBit now :) |
3 changes: 3 additions & 0 deletions
3
crates/moon/tests/test_cases/backend_in_mod_json.in/lib/hello.mbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test { | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
crates/moon/tests/test_cases/backend_in_mod_json.in/lib/moon.pkg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
4 changes: 4 additions & 0 deletions
4
crates/moon/tests/test_cases/backend_in_mod_json.in/main/main.mbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main { | ||
let 🤣 = 3 | ||
println(🤣) | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/moon/tests/test_cases/backend_in_mod_json.in/main/moon.pkg.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"is-main": true, | ||
"import": {} | ||
} |
4 changes: 4 additions & 0 deletions
4
crates/moon/tests/test_cases/backend_in_mod_json.in/moon.mod.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "unicode_demo", | ||
"backend": "js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,15 @@ | |
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use crate::common::{MoonModJSONFormatErrorKind, MooncOpt, NameError, MOON_PKG_JSON}; | ||
use crate::dependency::{ | ||
BinaryDependencyInfo, BinaryDependencyInfoJson, SourceDependencyInfo, SourceDependencyInfoJson, | ||
}; | ||
use crate::common::MoonModJSONFormatErrorKind; | ||
use crate::common::MooncOpt; | ||
use crate::common::NameError; | ||
use crate::common::TargetBackend; | ||
use crate::common::MOON_PKG_JSON; | ||
use crate::dependency::BinaryDependencyInfo; | ||
use crate::dependency::BinaryDependencyInfoJson; | ||
use crate::dependency::SourceDependencyInfo; | ||
use crate::dependency::SourceDependencyInfoJson; | ||
use crate::package::{AliasJSON, Package, PackageJSON}; | ||
use crate::path::ImportPath; | ||
use anyhow::bail; | ||
|
@@ -515,6 +520,8 @@ pub struct MoonMod { | |
|
||
pub include: Option<Vec<String>>, | ||
pub exclude: Option<Vec<String>>, | ||
|
||
pub backend: TargetBackend, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, JsonSchema)] | ||
|
@@ -600,6 +607,10 @@ pub struct MoonModJSON { | |
/// Files to exclude when publishing. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub exclude: Option<Vec<String>>, | ||
|
||
/// Restrict backend to build the module. | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub backend: Option<String>, | ||
} | ||
|
||
impl TryFrom<MoonModJSON> for MoonMod { | ||
|
@@ -627,6 +638,12 @@ impl TryFrom<MoonModJSON> for MoonMod { | |
|
||
let source = j.source.map(|s| if s.is_empty() { ".".into() } else { s }); | ||
|
||
let backend = if let Some(ref b) = j.backend { | ||
TargetBackend::str_to_backend(b).map_err(MoonModJSONFormatErrorKind::Backend)? | ||
} else { | ||
TargetBackend::WasmGC | ||
}; | ||
|
||
Ok(MoonMod { | ||
name: j.name, | ||
version, | ||
|
@@ -649,6 +666,8 @@ impl TryFrom<MoonModJSON> for MoonMod { | |
|
||
include: j.include, | ||
exclude: j.exclude, | ||
|
||
backend, | ||
}) | ||
} | ||
} | ||
|
@@ -678,6 +697,12 @@ pub fn convert_module_to_mod_json(m: MoonMod) -> MoonModJSON { | |
|
||
include: m.include, | ||
exclude: m.exclude, | ||
|
||
backend: if m.backend == TargetBackend::WasmGC { | ||
None | ||
} else { | ||
Some(m.backend.to_flag().to_string()) | ||
}, | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters