Skip to content

Commit d11a5e8

Browse files
committed
Remove gn, add bazel
Bazel build works so long as you copy the dll, but there's no good way to copy an artifact that I can find in Bazel.
1 parent 598d564 commit d11a5e8

File tree

12 files changed

+74
-21
lines changed

12 files changed

+74
-21
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
out/*
1+
dart-sdk/*
2+
bazel-*/

Diff for: BUILD.gn

-6
This file was deleted.

Diff for: README.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This is an attempt / POC to build the Dart VM into a dynamic library, importable in any platform Dart supports.
44

5-
This uses the same build system any style as the Dart SDK, partially so that it can be built from a parallel checkout of the Dart SDK source, and (potentially, maybe one day) be brought into the Dart SDK directly.
6-
75
## Eventual support
86

97
The hope is that the the dynamic library will eventually support the following targets:
@@ -28,8 +26,28 @@ None. I literally just started.
2826

2927
## Building
3028

31-
`TODO:`
29+
* Fetch the Dart SDK into this directory. Follow the instructions from [the dart repo](https://github.com/dart-lang/sdk/wiki/Building#source). Put it in `dart-sdk`. The code and scripts assume that this is where the dart-sdk lives.
30+
* Build the Dart libraries
31+
* There is a Dart script for doing this that will do some checks for you as well:
32+
```
33+
dart tools/build/build.dart
34+
```
3235

3336
## Contributing
3437

3538
`TODO:`
39+
40+
# What I Did
41+
42+
This section is as much for my benefit as for yours.
43+
44+
* Modify the BUILD.gn files to add a `libdart` target. This is done by applying the patch in `./dart_sdk.patch`
45+
* Make sure all correct environment variables are set
46+
* On Windows, these are set with the `setup_env.ps1` script. Specifically, you need to set `GYP_MSVS_OVERRIDE_PATH`, `GYP_MSVS_VERSION`, and `DEPOT_TOOLS_WIN_TOOLCHAIN=0`
47+
* Builds libdart with:
48+
```bash
49+
python ./tools/build.py --no-goma -m release libdart
50+
```
51+
* Revert the changes made to build files to leave a clean copy of the dart-sdk (this makes updating easier)
52+
* Build the dynamic library using the Bazel script
53+
* This puts the output in `out/lib/platform` and `out/include`. The various examples look for these directories, and these can be copied for use in other projects.

Diff for: WORKSPACE

Whitespace-only changes.

Diff for: dart_sdk.patch

3.13 KB
Binary file not shown.

Diff for: examples/simple_example/BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cc_binary(
2+
name = "simple_example",
3+
srcs = ["main.cpp"],
4+
data = [
5+
"//src:dyndart"
6+
],
7+
deps = [
8+
"//src:libdyndart"
9+
],
10+
dynamic_deps = [
11+
"//src:dyndart",
12+
],
13+
)

Diff for: examples/simple_example/BUILD.gn

-5
This file was deleted.

Diff for: examples/simple_example/main.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <stdio.h>
22

3-
int main() {
4-
5-
printf("Hello world");
6-
7-
return 0;
8-
}
3+
#include "src/dart_dll.h"
4+
5+
void main() {
6+
DartDll_Initialize();
7+
printf("Hello World!");
8+
}

Diff for: setup_env.ps1

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$Env:GYP_MSVS_OVERRIDE_PATH="C:\Program Files\Microsoft Visual Studio\2022\Community\"
2+
$Env:GYP_MSVS_VERSION=2019
3+
$Env:DEPOT_TOOLS_WIN_TOOLCHAIN=0

Diff for: src/BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cc_shared_library(
2+
name = "dyndart",
3+
roots = [ ":libdyndart" ],
4+
visibility = ["//visibility:public"],
5+
)
6+
7+
cc_library(
8+
name = "libdyndart",
9+
hdrs = [ "dart_dll.h" ],
10+
srcs = [ "dart_dll.cpp" ],
11+
visibility = ["//visibility:public"],
12+
copts = [ "/DDART_DLL_EXPORTING" ]
13+
)

Diff for: src/dart_dll.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <iostream>
2+
3+
#include "dart_dll.h"
4+
5+
void DartDll_Initialize() {
6+
std::cout << "Hello from DartDll_Initialize()";
7+
}

Diff for: src/dart_dll.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#ifdef DART_DLL_EXPORTING
4+
#define DART_DLL_EXPORT __declspec(dllexport)
5+
#else
6+
#define DART_DLL_EXPORT __declspec(dllimport)
7+
#endif
8+
9+
DART_DLL_EXPORT void DartDll_Initialize();

0 commit comments

Comments
 (0)