Skip to content

Commit b2a807b

Browse files
committed
Decouple runtime-only pd-vm from pd-edge ABI
1 parent 65462b3 commit b2a807b

8 files changed

Lines changed: 64 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ jobs:
1919
- uses: actions/checkout@v4
2020
with:
2121
path: rustscript
22-
- uses: actions/checkout@v4
23-
with:
24-
repository: rustscript-lang/pd-edge
25-
path: pd-edge
2622
- uses: dtolnay/rust-toolchain@stable
2723
with:
2824
components: rustfmt, clippy
2925
- name: Format check
3026
working-directory: rustscript
3127
run: cargo fmt --all -- --check
28+
- name: Runtime-only dependency check
29+
working-directory: rustscript
30+
run: cargo check -p pd-vm --no-default-features --features runtime
3231
- name: Clippy
3332
working-directory: rustscript
3433
run: cargo clippy --workspace --all-targets --all-features
@@ -47,10 +46,6 @@ jobs:
4746
- uses: actions/checkout@v4
4847
with:
4948
path: rustscript
50-
- uses: actions/checkout@v4
51-
with:
52-
repository: rustscript-lang/pd-edge
53-
path: pd-edge
5449
- uses: dtolnay/rust-toolchain@stable
5550
- name: Build pd-vm CLI
5651
working-directory: rustscript

.github/workflows/publish-crates.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ jobs:
3939
uses: actions/checkout@v4
4040
with:
4141
path: rustscript
42-
- name: Checkout pd-edge dependency
43-
uses: actions/checkout@v4
44-
with:
45-
repository: rustscript-lang/pd-edge
46-
path: pd-edge
4742
- name: Setup Rust
4843
uses: dtolnay/rust-toolchain@stable
4944
- name: Publish crates

Cargo.lock

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ name = "vm"
2626
[features]
2727
default = ["runtime", "cli", "cranelift-jit", "http", "tls", "websocket"]
2828
runtime = []
29-
http = ["edge_abi/http"]
29+
edge-abi = ["dep:edge_abi"]
30+
http = ["edge-abi", "edge_abi/http"]
3031
http2 = ["http", "edge_abi/http2"]
31-
mqtt = ["edge_abi/mqtt"]
32+
mqtt = ["edge-abi", "edge_abi/mqtt"]
3233
tls = ["http", "edge_abi/tls"]
3334
websocket = ["http", "edge_abi/websocket"]
3435
webrtc = ["http", "edge_abi/webrtc"]
@@ -55,7 +56,7 @@ cranelift-jit = { version = "0.129.1", optional = true }
5556
cranelift-module = { version = "0.129.1", optional = true }
5657
cranelift-native = { version = "0.129.1", optional = true }
5758
pd-host-function = { path = "./pd-host-function", version = "0.1.0" }
58-
edge_abi = { package = "pd-edge-abi", path = "../pd-edge/pd-edge-abi", version = "0.1.0", default-features = false }
59+
edge_abi = { package = "pd-edge-abi", version = "0.1.1", default-features = false, optional = true }
5960
futures-channel = "0.3"
6061
paste = "1"
6162
regex = "1"

pd-vm-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ runtime = ["vm/runtime"]
1616
serde = { version = "1", features = ["derive"] }
1717
serde_json = "1"
1818
vm = { package = "pd-vm", path = "..", default-features = false }
19-
edge_abi = { package = "pd-edge-abi", path = "../../pd-edge/pd-edge-abi" }
19+
edge_abi = { package = "pd-edge-abi", version = "0.1.1" }

src/compiler/ir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub struct StructDecl {
117117
}
118118

119119
fn known_host_accepts_arity(name: &str, arity: u8) -> bool {
120+
#[cfg(feature = "edge-abi")]
120121
if let Some(function) = edge_abi::function_by_name(name) {
121122
return function.param_types.len() == usize::from(arity);
122123
}

src/compiler/parser/symbols.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub(super) fn is_virtual_host_namespace_spec(spec: &str) -> bool {
1414
is_ident_start(first) && chars.all(is_ident_continue)
1515
}
1616

17+
#[cfg(feature = "edge-abi")]
1718
fn abi_value_type_to_value_type(value: edge_abi::AbiValueType) -> ValueType {
1819
match value {
1920
edge_abi::AbiValueType::Unknown => ValueType::Unknown,
@@ -29,15 +30,25 @@ fn abi_value_type_to_value_type(value: edge_abi::AbiValueType) -> ValueType {
2930
}
3031

3132
fn known_host_return_type(name: &str) -> ValueType {
32-
edge_abi::function_by_name(name)
33-
.map(|function| abi_value_type_to_value_type(function.return_type))
33+
edge_host_return_type(name)
3434
.or_else(|| {
3535
default_host_callable(name)
3636
.and_then(|callable| parse_host_return_value_type(callable.signature.return_type))
3737
})
3838
.unwrap_or(ValueType::Unknown)
3939
}
4040

41+
#[cfg(feature = "edge-abi")]
42+
fn edge_host_return_type(name: &str) -> Option<ValueType> {
43+
edge_abi::function_by_name(name)
44+
.map(|function| abi_value_type_to_value_type(function.return_type))
45+
}
46+
47+
#[cfg(not(feature = "edge-abi"))]
48+
fn edge_host_return_type(_name: &str) -> Option<ValueType> {
49+
None
50+
}
51+
4152
fn known_host_return_schema(name: &str) -> Option<TypeSchema> {
4253
default_host_callable(name)
4354
.and_then(|callable| parse_host_return_schema(callable.signature.return_type))
@@ -102,6 +113,7 @@ fn parse_simple_host_return_schema(spec: &str) -> Option<TypeSchema> {
102113
}
103114

104115
fn known_host_accepts_arity(name: &str, arity: u8) -> bool {
116+
#[cfg(feature = "edge-abi")]
105117
if let Some(function) = edge_abi::function_by_name(name) {
106118
return function.param_types.len() == usize::from(arity);
107119
}

src/compiler/typing/helpers.rs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::{HashMap, HashSet};
22

3-
use crate::builtins::{BuiltinFunction, CallableParam, CallableParamType};
3+
use crate::builtins::BuiltinFunction;
4+
#[cfg(feature = "edge-abi")]
5+
use crate::builtins::{CallableParam, CallableParamType};
46

57
use super::super::CompileError;
68
use super::super::TypingMode;
@@ -1221,23 +1223,30 @@ pub(super) fn known_host_signature(name: &str) -> Option<HostCallableSignature>
12211223
});
12221224
}
12231225

1224-
let function = edge_abi::function_by_name(name)?;
1225-
Some(HostCallableSignature {
1226-
name: name.to_string(),
1227-
params: function
1228-
.param_names
1229-
.iter()
1230-
.copied()
1231-
.zip(function.param_types.iter().copied())
1232-
.map(|(param_name, param_type)| CallableParam {
1233-
name: param_name,
1234-
ty: callable_param_type_from_abi(param_type),
1235-
optional: false,
1236-
})
1237-
.collect(),
1238-
})
1226+
#[cfg(feature = "edge-abi")]
1227+
{
1228+
let function = edge_abi::function_by_name(name)?;
1229+
Some(HostCallableSignature {
1230+
name: name.to_string(),
1231+
params: function
1232+
.param_names
1233+
.iter()
1234+
.copied()
1235+
.zip(function.param_types.iter().copied())
1236+
.map(|(param_name, param_type)| CallableParam {
1237+
name: param_name,
1238+
ty: callable_param_type_from_abi(param_type),
1239+
optional: false,
1240+
})
1241+
.collect(),
1242+
})
1243+
}
1244+
1245+
#[cfg(not(feature = "edge-abi"))]
1246+
None
12391247
}
12401248

1249+
#[cfg(feature = "edge-abi")]
12411250
pub(super) fn callable_param_type_from_abi(value: edge_abi::AbiParamType) -> CallableParamType {
12421251
match value {
12431252
edge_abi::AbiParamType::Any => CallableParamType::Any,

0 commit comments

Comments
 (0)