Skip to content

Commit de64023

Browse files
committed
✨ Add the ability to configure the vm service isolate port
1 parent 9efc655 commit de64023

File tree

7 files changed

+37
-17
lines changed

7 files changed

+37
-17
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ You need
3131
* git
3232
* All the things to get Dart source - https://github.com/dart-lang/sdk/wiki/Building#source
3333
* C++ build tools for your platform (Visual Studio, XCode, gcc, etc)
34+
* CMake
3435

3536
## Contributing
3637

@@ -45,19 +46,15 @@ This section is as much for my benefit as for yours. Eventually, I hope to make
4546
* 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`
4647
* Builds libdart with:
4748
```bash
48-
python ./tools/build.py --no-goma -m release libdart
49+
# On windows, you will need to add `python` in front
50+
./tools/build.py --no-goma -m release libdart
4951
```
5052
* Revert the changes made to build files to leave a clean copy of the dart-sdk (this makes updating easier)
51-
* Generate build scripts with genie:
52-
```bash
53-
// Windows
54-
tools/win/genie.exe vs2022
55-
// MacOS
56-
./tools/mac/genie xcode11
57-
```
58-
* Open the generated build files (in ./.build/projects/[arch_platform]) and build the project.
59-
* Build.
60-
* Run one of the examples!
53+
* Build with CMake:
54+
```
55+
cmake -B ./.build .
56+
cmake --build ./.build
57+
```
6158

6259
Updating the dart-sdk
6360
* Make sure environment variables are set (`setup_env.ps1`)

examples/simple_example/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ Dart_NativeFunction ResolveNativeFunction(Dart_Handle name,
4343

4444
int main() {
4545
// Initialize Dart
46-
if (!DartDll_Initialize()) {
46+
DartDllConfig config;
47+
config.service_port = 6222;
48+
49+
if (!DartDll_Initialize(config)) {
4750
return -1;
4851
}
4952

examples/simple_example_ffi/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void* ResolveNativeFunction(const char* name, uintptr_t args_n) {
2828

2929
int main() {
3030
// Initialize Dart
31-
if (!DartDll_Initialize()) {
31+
if (!DartDll_Initialize(DartDllConfig())) {
3232
return -1;
3333
}
3434

src/dart_dll.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
using namespace dart::bin;
1515

16+
static DartDllConfig _dart_dll_config;
17+
1618
extern "C" {
1719
extern const uint8_t kDartVmSnapshotData[];
1820
extern const uint8_t kDartVmSnapshotInstructions[];
@@ -51,7 +53,8 @@ static Dart_Isolate CreateIsolateGroupAndSetup(const char* script_uri,
5153
flags, callback_data, error);
5254
} else if (0 == strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME)) {
5355
return CreateVmServiceIsolate(script_uri, main, package_root,
54-
package_config, flags, callback_data, error);
56+
package_config, flags, callback_data,
57+
_dart_dll_config.service_port, error);
5558
} else {
5659
return CreateIsolate(false, script_uri, main, package_config, flags,
5760
callback_data, error);
@@ -102,7 +105,7 @@ static void DeleteIsolateGroupData(void* callback_data) {
102105

103106
extern "C" {
104107

105-
bool DartDll_Initialize() {
108+
bool DartDll_Initialize(const DartDllConfig& config) {
106109
std::cout << "Initializig Dart ---- \n";
107110

108111
Dart_SetVMFlags(0, nullptr);
@@ -113,6 +116,9 @@ bool DartDll_Initialize() {
113116
return false;
114117
}
115118

119+
// copy the configuration
120+
memcpy(&_dart_dll_config, &config, sizeof(DartDllConfig));
121+
116122
dfe.Init();
117123
dfe.set_use_dfe();
118124
dfe.set_use_incremental_compiler(true);

src/dart_dll.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,20 @@ typedef struct _Dart_Handle* Dart_Handle;
1515

1616
extern "C" {
1717

18+
struct DartDllConfig {
19+
bool start_service_isolate;
20+
int service_port;
21+
22+
DartDllConfig()
23+
: start_service_isolate(true)
24+
, service_port(5858)
25+
{
26+
27+
}
28+
};
29+
1830
// Initialize Dart
19-
DART_DLL_EXPORT bool DartDll_Initialize();
31+
DART_DLL_EXPORT bool DartDll_Initialize(const DartDllConfig& config);
2032

2133
// Load a script, with an optional package configuration location. The package
2234
// configuration is usually in ".dart_tool/package_config.json".

src/isolate_setup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Dart_Isolate CreateVmServiceIsolate(const char* script_uri,
100100
const char* package_config,
101101
Dart_IsolateFlags* flags,
102102
void* callback_data,
103+
int service_port,
103104
char** error) {
104105
IsolateGroupData* isolate_group_data =
105106
new IsolateGroupData(script_uri, package_config, nullptr, false);
@@ -114,7 +115,7 @@ Dart_Isolate CreateVmServiceIsolate(const char* script_uri,
114115
isolate_group_data, isolate_data};
115116

116117
dart::embedder::VmServiceConfiguration vm_config = {
117-
"127.0.0.1", 5858, nullptr, true, true, true};
118+
"127.0.0.1", service_port, nullptr, true, true, true};
118119

119120
Dart_Isolate isolate = dart::embedder::CreateVmServiceIsolate(
120121
data, vm_config, isolate_snapshot_data, isolate_snapshot_instructions,

src/isolate_setup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Dart_Isolate CreateVmServiceIsolate(const char* script_uri,
1616
const char* package_config,
1717
Dart_IsolateFlags* flags,
1818
void* callback_data,
19+
int service_port,
1920
char** error);
2021

2122
Dart_Isolate CreateIsolate(bool is_main_isolate,

0 commit comments

Comments
 (0)