Dart 3 macros examples ⬆
Directory macros-examples\ contains Dart 3 code examples using macros and coming from various websites.
|
Example bird
has the following directory structure :
> tree /f /a . | findstr /v /b [A-Z] | 00download.txt | analysis_options.yaml | build.bat | build.sh | Makefile | pubspec.yaml \---src \---main \---dart Awesome.dart Bird.dart main.dart
Command build.bat run
generates the executable bird.exe
from source file main.dart
and runs it.
> build -verbose run Resolve project dependencies Resolving dependencies... Downloading packages... + _macros 0.3.2 from sdk dart + macros 0.1.2-main.4 (0.1.3-main.0 available) Changed 2 dependencies! 1 package has newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. Compile 1 Dart source file into directory "target" Execute program "target\bird.exe" Macros are awesome Bird
In the same way command make.exe
executes the build commands clean
and run
defined in project file Makefile
(use option -q
to hide progress messages) :
> make clean run "/usr/bin/rm.exe" -rf "target" [ -d "target" ] || "/usr/bin/mkdir.exe" -p "target" "C:/opt/dart-sdk/bin/dart.exe" pub upgrade Resolving dependencies... Downloading packages... macros 0.1.2-main.4 (0.1.3-main.0 available) No dependencies changed. 1 package has newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. "C:/opt/dart-sdk/bin/dart.exe" compile exe --enable-experiment=macros --output "F:\macros-examples\bird\target\bird.exe" "F:\macros-examples\bird\src\main\dart\main.dart" Generated: f:\macros-examples\bird\target\bird.exe target/bird.exe Macros are awesome Bird
Finally, the bash script build.sh
works in the same way as batch file build.bat
:
> sh build.sh clean run Resolving dependencies... Downloading packages... + _macros 0.3.2 from sdk dart + macros 0.1.2-main.4 (0.1.3-main.0 available) Changed 2 dependencies! 1 package has newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. Generated: f:\macros-examples\bird\target\bird.exe Macros are awesome Bird
Example userJson
has the following directory structure :
> tree /f /a . | findstr /v /b [A-Z] | 00download.txt | analysis_options.yaml | build.bat | build.sh | pubspec.yaml \---src \---main \---dart main.dart User.dart
Command build.bat run
generates the executable userJson.exe
from source file main.dart
and runs it.
> build -verbose run Resolve project dependencies Resolving dependencies... Downloading packages... + _macros 0.3.2 from sdk dart + json 0.20.2 (0.20.4 available) + macros 0.1.2-main.4 (0.1.3-main.0 available) Changed 3 dependencies! 2 packages have newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. Compile 1 Dart source file into directory "target" Execute program "target\userJson.exe" Instance of 'User' {age: 5, name: Roger, username: roger1337}
In the same way command make.exe
executes the build commands clean
and run
defined in project file Makefile
(use option -q
to hide progress messages) :
> make clean run "/usr/bin/rm.exe" -rf "target" [ -d "target" ] || "/usr/bin/mkdir.exe" -p "target" "C:/opt/dart-sdk/bin/dart.exe" pub upgrade Resolving dependencies... Downloading packages... json 0.20.2 (0.20.4 available) macros 0.1.2-main.4 (0.1.3-main.0 available) No dependencies changed. 2 packages have newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. "C:/opt/dart-sdk/bin/dart.exe" compile exe --enable-experiment=macros --output "F:\macros-examples\userJson\target\userJson.exe" "F:\macros-examples\userJson\src\main\dart\main.dart" Generated: f:\macros-examples\userjson\target\userjson.exe target/userJson.exe Instance of 'User' {age: 5, name: Roger, username: roger1337}
Finally, the bash script build.sh
works in the same way as batch file build.bat
:
> sh build.sh clean run Resolving dependencies... Downloading packages... json 0.20.2 (0.20.4 available) macros 0.1.2-main.4 (0.1.3-main.0 available) No dependencies changed. 2 packages have newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. Generated: f:\macros-examples\userjson\target\userjson.exe Instance of 'User' {age: 5, name: Roger, username: roger1337}