As mentioned on README, Dart 3.4.0 supports DART_VM_OPTIONS for self-executables:
README.md:
...
### Dart Runtime
- Dart VM flags and options can now be provided to any executable generated
using `dart compile exe` via the `DART_VM_OPTIONS` environment variable.
`DART_VM_OPTIONS` should be set to a list of comma-separated flags and options
with no whitespace. Options that allow for multiple values to be provided as
comma-separated values are not supported (e.g.,
`--timeline-streams=Dart,GC,Compiler`).
Example of a valid `DART_VM_OPTIONS` environment variable:
DART_VM_OPTIONS=--random_seed=42,--verbose_gc
...
Example:
foo.dart:
void main(List<String> args) {
print("FOO>> args: $args");
}
run-foo.sh:
#!/bin/bash
dart compile exe foo.dart
export DART_VM_OPTIONS=--random_seed=42,--verbose_gc
echo "DART_VM_OPTIONS: $DART_VM_OPTIONS"
echo "Running executable:"
./foo.exe
Output of ./run-foo.sh:
Generated: /private/tmp/dart-test-foo/foo.exe
DART_VM_OPTIONS: --random_seed=42,--verbose_gc
Running executable:
Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]
Executes the Dart script <dart-script-file> with the given list of <script-arguments>.
Common VM flags:
--help or -h
Display this message (add -v or --verbose for information about
all VM options).
--packages=<path>
Where to find a package spec file.
--define=<key>=<value> or -D<key>=<value>
Define an environment declaration. To specify multiple declarations,
use multiple instances of this option.
--snapshot-kind=<snapshot_kind>
--snapshot=<file_name>
These snapshot options are used to generate a snapshot of the loaded
Dart script:
<snapshot-kind> controls the kind of snapshot, it could be
kernel(default) or app-jit
<file_name> specifies the file into which the snapshot is written
--version
Print the SDK version.
For some reason it's always showing the dart CLI help message.
dart --version:
Dart SDK version: 3.4.0 (stable) (Mon May 6 07:59:58 2024 -0700) on "macos_x64"
As mentioned on README, Dart 3.4.0 supports
DART_VM_OPTIONSfor self-executables:README.md:Example:
foo.dart:run-foo.sh:Output of
./run-foo.sh:For some reason it's always showing the
dartCLI help message.dart --version: