@@ -8,7 +8,7 @@ use crate as vm;
88use 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
833833fn 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+
864893fn 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
877906fn 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