diff --git a/runtime/engine/BUILD.gn b/runtime/engine/BUILD.gn index ed11c8184b8..6dd85e65876 100644 --- a/runtime/engine/BUILD.gn +++ b/runtime/engine/BUILD.gn @@ -107,3 +107,37 @@ shared_library("dart_engine_aot_shared") { ] } } + +static_library("dart_engine_jit_static") { + deps = [ ":engine_jit_set" ] + complete_static_lib = true + + if (is_win) { + libs = [ + "ole32.lib", + "iphlpapi.lib", + "psapi.lib", + "ws2_32.lib", + "Rpcrt4.lib", + "shlwapi.lib", + "winmm.lib", + ] + } +} + +static_library("dart_engine_aot_static") { + deps = [ ":engine_aot_set" ] + complete_static_lib = true + + if (is_win) { + libs = [ + "ole32.lib", + "iphlpapi.lib", + "psapi.lib", + "ws2_32.lib", + "Rpcrt4.lib", + "shlwapi.lib", + "winmm.lib", + ] + } +} diff --git a/runtime/tools/entitlements/run_futures_aot_static.plist b/runtime/tools/entitlements/run_futures_aot_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_futures_aot_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_futures_kernel_static.plist b/runtime/tools/entitlements/run_futures_kernel_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_futures_kernel_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_main_aot_static.plist b/runtime/tools/entitlements/run_main_aot_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_main_aot_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_main_kernel_static.plist b/runtime/tools/entitlements/run_main_kernel_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_main_kernel_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_timer_aot_static.plist b/runtime/tools/entitlements/run_timer_aot_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_timer_aot_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_timer_async_aot_static.plist b/runtime/tools/entitlements/run_timer_async_aot_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_timer_async_aot_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_timer_async_kernel_static.plist b/runtime/tools/entitlements/run_timer_async_kernel_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_timer_async_kernel_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_timer_kernel_static.plist b/runtime/tools/entitlements/run_timer_kernel_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_timer_kernel_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_two_programs_aot_static.plist b/runtime/tools/entitlements/run_two_programs_aot_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_two_programs_aot_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/runtime/tools/entitlements/run_two_programs_kernel_static.plist b/runtime/tools/entitlements/run_two_programs_kernel_static.plist new file mode 100644 index 00000000000..eeda4be95dc --- /dev/null +++ b/runtime/tools/entitlements/run_two_programs_kernel_static.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.disable-library-validation + + + \ No newline at end of file diff --git a/samples/embedder/BUILD.gn b/samples/embedder/BUILD.gn index 5f990dcacfb..0b416107c14 100644 --- a/samples/embedder/BUILD.gn +++ b/samples/embedder/BUILD.gn @@ -16,28 +16,42 @@ group("all") { group("aot") { deps = [ ":run_main_aot", + ":run_main_aot_static", ":run_timer_aot", + ":run_timer_aot_static", ":run_timer_async_aot", + ":run_timer_async_aot_static", ":run_two_programs_aot", + ":run_two_programs_aot_static", ] # FFI can't execute on the VM's simulator if (dart_target_arch == host_cpu) { - deps += [ ":run_futures_aot" ] + deps += [ + ":run_futures_aot", + ":run_futures_aot_static", + ] } } group("kernel") { deps = [ ":run_main_kernel", + ":run_main_kernel_static", ":run_timer_async_kernel", + ":run_timer_async_kernel_static", ":run_timer_kernel", + ":run_timer_kernel_static", ":run_two_programs_kernel", + ":run_two_programs_kernel_static", ] # FFI can't execute on the VM's simulator if (dart_target_arch == host_cpu) { - deps += [ ":run_futures_kernel" ] + deps += [ + ":run_futures_kernel", + ":run_futures_kernel_static", + ] } } @@ -45,6 +59,7 @@ _all_configs = [ { suffix = "_kernel" dart_shared_lib = "../../runtime/engine:dart_engine_jit_shared" + dart_static_lib = "../../runtime/engine:dart_engine_jit_static" dart_snapshot_kind = "kernel" gen_kernel_args = [ "--link-platform" ] snapshot_target = "application_snapshot" @@ -53,6 +68,7 @@ _all_configs = [ { suffix = "_aot" dart_shared_lib = "../../runtime/engine:dart_engine_aot_shared" + dart_static_lib = "../../runtime/engine:dart_engine_aot_static" snapshot_target = "aot_snapshot" # AOT snapshots as shared libraries on Windows are not @@ -105,6 +121,37 @@ template("sample") { } deps += extra_deps } + + executable("${target_name}${conf.suffix}_static") { + forward_variables_from(invoker, + "*", + [ + "extra_deps", + "configurable_deps", + ]) + if (!defined(include_dirs)) { + include_dirs = [] + } + + include_dirs += [ + ".", + "../../runtime", + "../../runtime/engine", + ] + + # Otherwise build with --no-clang (jit) or MSAN (aot) fails. + if (is_linux) { + if (!defined(ldflags)) { + ldflags = [] + } + ldflags += [ "-Wl,--allow-shlib-undefined" ] + } + deps = [ conf.dart_static_lib ] + foreach(dep, configurable_deps) { + deps += [ "${dep}${conf.suffix}_static" ] + } + deps += extra_deps + } } } @@ -118,7 +165,8 @@ template("snapshots") { extra_deps += invoker.extra_deps } foreach(conf, _all_configs) { - target(conf.snapshot_target, "${target_name}${conf.suffix}") { + snapshot_target_name = "${target_name}${conf.suffix}" + target(conf.snapshot_target, snapshot_target_name) { forward_variables_from(invoker, "*", [ @@ -143,6 +191,9 @@ template("snapshots") { } deps += extra_deps } + group("${snapshot_target_name}_static") { + deps = [ ":${snapshot_target_name}" ] + } } } @@ -197,6 +248,35 @@ template("shims") { } deps += extra_deps } + + static_library("${target_name}${conf.suffix}_static") { + forward_variables_from(invoker, + "*", + [ + "name", + "extra_deps", + "configurable_deps", + ]) + if (!defined(include_dirs)) { + include_dirs = [] + } + include_dirs += [ + ".", + "../../runtime", + "../../runtime/engine", + ] + + sources = [ + "$name.cc", + "$name.h", + ] + public = [ "$name.h" ] + deps = [ conf.dart_static_lib ] + foreach(dep, configurable_deps) { + deps += [ "$dep${conf.suffix}" ] + } + deps += extra_deps + } } } diff --git a/tests/standalone/embedder_samples_test.dart b/tests/standalone/embedder_samples_test.dart index 40d9009d8b0..94bd1d4855d 100644 --- a/tests/standalone/embedder_samples_test.dart +++ b/tests/standalone/embedder_samples_test.dart @@ -2,6 +2,17 @@ import 'dart:io'; import 'package:expect/expect.dart'; +void checkSamples( + String binaryBasename, + List args, { + bool skipIfNotBuilt = false, +}) { + // Shared library variant. + checkSample(binaryBasename, args, skipIfNotBuilt: skipIfNotBuilt); + // Static variant. + checkSample('${binaryBasename}_static', args, skipIfNotBuilt: skipIfNotBuilt); +} + void checkSample( String binary, List args, { @@ -35,35 +46,37 @@ void main() { final executable = File(Platform.executable).absolute.path; final out = executable.substring(0, executable.lastIndexOf('dart') - 1); - checkSample('$out/run_main_kernel', ['$out/gen/hello_kernel.dart.snapshot']); - checkSample('$out/run_two_programs_kernel', [ + checkSamples('$out/run_main_kernel', ['$out/gen/hello_kernel.dart.snapshot']); + checkSamples('$out/run_two_programs_kernel', [ '$out/gen/program1_kernel.dart.snapshot', '$out/gen/program2_kernel.dart.snapshot', ]); - checkSample('$out/run_timer_kernel', ['$out/gen/timer_kernel.dart.snapshot']); - checkSample('$out/run_timer_async_kernel', [ + checkSamples('$out/run_timer_kernel', [ + '$out/gen/timer_kernel.dart.snapshot', + ]); + checkSamples('$out/run_timer_async_kernel', [ '$out/gen/timer_kernel.dart.snapshot', ]); // FFI samples aren't built on some platforms. - checkSample('$out/run_futures_kernel', [ + checkSamples('$out/run_futures_kernel', [ '$out/gen/futures_kernel.dart.snapshot', ], skipIfNotBuilt: true); // AOT Samples aren't built on some platforms. - checkSample('$out/run_main_aot', [ + checkSamples('$out/run_main_aot', [ '$out/hello_aot.snapshot', ], skipIfNotBuilt: true); - checkSample('$out/run_two_programs_aot', [ + checkSamples('$out/run_two_programs_aot', [ '$out/program1_aot.snapshot', '$out/program2_aot.snapshot', ], skipIfNotBuilt: true); - checkSample('$out/run_timer_aot', [ + checkSamples('$out/run_timer_aot', [ '$out/timer_aot.snapshot', ], skipIfNotBuilt: true); - checkSample('$out/run_timer_async_aot', [ + checkSamples('$out/run_timer_async_aot', [ '$out/timer_aot.snapshot', ], skipIfNotBuilt: true); - checkSample('$out/run_futures_aot', [ + checkSamples('$out/run_futures_aot', [ '$out/futures_aot.snapshot', ], skipIfNotBuilt: true); }