Skip to content

Commit 5dda822

Browse files
committed
Simplify edge ABI feature reporting
1 parent 1f3aaee commit 5dda822

3 files changed

Lines changed: 69 additions & 17 deletions

File tree

Cargo.toml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ repository = "https://github.com/rustscript-lang/rustscript"
2525
name = "vm"
2626

2727
[features]
28-
default = ["runtime", "cli", "cranelift-jit", "http", "tls", "websocket"]
28+
default = ["runtime", "cli", "cranelift-jit"]
2929
runtime = []
30-
edge-abi = ["dep:edge_abi"]
31-
http = ["edge-abi", "edge_abi/http"]
32-
http2 = ["http", "edge_abi/http2"]
33-
mqtt = ["edge-abi", "edge_abi/mqtt"]
34-
tls = ["http", "edge_abi/tls"]
35-
websocket = ["http", "edge_abi/websocket"]
36-
webrtc = ["http", "edge_abi/webrtc"]
30+
edge-abi = [
31+
"dep:edge_abi",
32+
"edge_abi/console",
33+
"edge_abi/http",
34+
"edge_abi/http2",
35+
"edge_abi/mqtt",
36+
"edge_abi/tls",
37+
"edge_abi/websocket",
38+
"edge_abi/webrtc",
39+
]
3740
cli = ["dep:rustyline", "runtime"]
3841
cranelift-jit = [
3942
"runtime",

crates/rustscript/Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ homepage = "https://rustscript.org/"
1111
name = "rustscript"
1212

1313
[features]
14-
default = ["runtime", "cli", "cranelift-jit", "http", "tls", "websocket"]
14+
default = ["runtime", "cli", "cranelift-jit"]
1515
runtime = ["pd_vm_crate/runtime"]
16-
http = ["pd_vm_crate/http"]
17-
http2 = ["pd_vm_crate/http2"]
18-
mqtt = ["pd_vm_crate/mqtt"]
19-
tls = ["pd_vm_crate/tls"]
20-
websocket = ["pd_vm_crate/websocket"]
21-
webrtc = ["pd_vm_crate/webrtc"]
16+
edge-abi = ["pd_vm_crate/edge-abi"]
2217
cli = ["pd_vm_crate/cli"]
2318
cranelift-jit = ["pd_vm_crate/cranelift-jit"]
2419

src/cli.rs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate as vm;
88
use crate::{
99
CallOutcome, CallReturn, CompileSourceFileOptions, Debugger, DisassembleOptions, JitConfig,
1010
OpCode, Program, ReplLocalBinding, SourceFlavor, SourceMap, SourcePathError, Value, Vm,
11-
VmError, VmRecording, VmStatus, compile_source_file_with_options,
11+
VmError, VmRecording, VmStatus, builtin_namespace_specs, compile_source_file_with_options,
1212
disassemble_vmbc_with_options, encode_program, format_source_with_flavor_and_options,
1313
render_source_error, render_vm_error, replay_recording_stdio,
1414
};
@@ -831,6 +831,8 @@ fn cli_host_registry() -> &'static HostFunctionRegistry {
831831
}
832832

833833
fn print_usage(binary_name: &str) {
834+
println!("features: {}", cli_build_feature_summary());
835+
println!();
834836
println!("Usage:");
835837
println!(" {binary_name} (defaults to REPL)");
836838
println!(" {binary_name} --version");
@@ -861,6 +863,33 @@ fn print_usage(binary_name: &str) {
861863
println!(" --check In fmt mode, fail if formatting would change the file");
862864
}
863865

866+
fn cli_build_features() -> Vec<String> {
867+
let mut features = Vec::new();
868+
if cfg!(feature = "cranelift-jit") {
869+
features.push("cranelift-jit".to_string());
870+
}
871+
if cfg!(feature = "runtime") {
872+
features.push("runtime".to_string());
873+
}
874+
if CompileSourceFileOptions::default()
875+
.module_override_source("stdlib/rss/strings.rss")
876+
.is_some()
877+
{
878+
features.push("stdlibs".to_string());
879+
}
880+
let modules = builtin_namespace_specs()
881+
.iter()
882+
.map(|spec| spec.namespace)
883+
.collect::<Vec<_>>()
884+
.join(", ");
885+
features.push(format!("modules={modules}"));
886+
features
887+
}
888+
889+
fn cli_build_feature_summary() -> String {
890+
cli_build_features().join(", ")
891+
}
892+
864893
fn binary_version_text(binary: &str) -> String {
865894
let git_tag = option_env!("PD_BUILD_GIT_TAG").unwrap_or("untagged");
866895
let git_commit = option_env!("PD_BUILD_GIT_COMMIT").unwrap_or("unknown");
@@ -876,6 +905,7 @@ fn binary_version_text(binary: &str) -> String {
876905

877906
fn run_repl() -> Result<(), Box<dyn std::error::Error>> {
878907
println!("pd-vm REPL (RustScript)");
908+
println!("features: {}", cli_build_feature_summary());
879909
println!("history: up/down arrows, commands: .help, .quit, .cancel");
880910
let mut editor = DefaultEditor::new()?;
881911
let mut session = ReplSession::default();
@@ -1463,12 +1493,36 @@ mod tests {
14631493
CliConfig, parse_cli_args, prepare_aot_for_cli, register_imports,
14641494
try_new_cli_vm_from_standalone_aot,
14651495
};
1466-
use vm::{HostImport, OpCode, Program, Value, ValueType, Vm, VmStatus};
1496+
use vm::{
1497+
CompileSourceFileOptions, HostImport, OpCode, Program, Value, ValueType, Vm, VmStatus,
1498+
};
14671499

14681500
fn s(value: &str) -> String {
14691501
value.to_string()
14701502
}
14711503

1504+
#[test]
1505+
fn cli_build_features_report_compiled_capabilities() {
1506+
let features = super::cli_build_features();
1507+
1508+
assert_eq!(
1509+
features,
1510+
vec![
1511+
cfg!(feature = "cranelift-jit").then_some("cranelift-jit".to_string()),
1512+
cfg!(feature = "runtime").then_some("runtime".to_string()),
1513+
CompileSourceFileOptions::default()
1514+
.module_override_source("stdlib/rss/strings.rss")
1515+
.is_some()
1516+
.then_some("stdlibs".to_string()),
1517+
Some("modules=bytes, io, re, json, jit, math".to_string()),
1518+
]
1519+
.into_iter()
1520+
.flatten()
1521+
.collect::<Vec<_>>()
1522+
);
1523+
assert!(!super::cli_build_feature_summary().contains("enabled"));
1524+
}
1525+
14721526
fn native_aot_supported() -> bool {
14731527
(cfg!(target_arch = "x86_64")
14741528
&& (cfg!(target_os = "windows") || (cfg!(unix) && !cfg!(target_os = "macos"))))

0 commit comments

Comments
 (0)