Skip to content

Commit ccf38cf

Browse files
authored
Runtime builder and wasm support (#7)
1 parent 98fb470 commit ccf38cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3520
-156
lines changed

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"BazelBuild.vscode-bazel",
4+
"ms-dotnettools.csharp"
5+
]
6+
}

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"editor.insertSpaces": false,
3+
"files.insertFinalNewline": true,
4+
"[starlark]": {
5+
"editor.formatOnSave": true,
6+
"editor.defaultFormatter": "BazelBuild.vscode-bazel"
7+
}
8+
}

WORKSPACE

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
55

66
git_repository(
7-
name = "ecsact",
8-
remote = "git@github.com:seaube/ecsact.git",
9-
commit = "6bce75438e812fd887dbe24e757d2a523993fa26",
10-
shallow_since = "1651763515 -0400",
7+
name = "ecsact_rtb",
8+
commit = "4d4856d697300a1e3c8b2e49b25acb72e9328b9d",
9+
remote = "git@github.com:seaube/ecsact-rtb.git",
10+
# shallow_since = "1657554031 -0700",
1111
)
1212

13-
http_archive(
14-
name = "boost",
15-
strip_prefix = "boost-563e8e0de4eac4b48a02d296581dc2454127608e",
16-
urls = ["https://github.com/bazelboost/boost/archive/563e8e0de4eac4b48a02d296581dc2454127608e.zip"],
17-
sha256 = "c41441a6e9f8038ad626e9f937ddc3675ab896b6c3512eefc6840037b3816d03",
18-
)
13+
load("@ecsact_rtb//:repositories.bzl", "ecsact_rtb_repositories")
14+
15+
ecsact_rtb_repositories()
1916

20-
load("@boost//:index.bzl", "boost_http_archives")
21-
boost_http_archives()
17+
load("@ecsact_rtb//:workspace.bzl", "ecsact_rtb_workspace")
18+
19+
ecsact_rtb_workspace()
2220

2321
http_archive(
2422
name = "bzlws",
25-
strip_prefix = "bzlws-f929e5380f441f50a77776d34a7df8cacdbdf986",
26-
url = "https://github.com/zaucy/bzlws/archive/f929e5380f441f50a77776d34a7df8cacdbdf986.zip",
27-
sha256 = "5bebb821b158b11d81dd25cf031b5b26bae97dbb02025df7d0e41a262b3a030b",
23+
sha256 = "9bc9d6bf1d885992d58a4ad9dc7476a8cd48d672b497707b0ae2c0899c6d369b",
24+
strip_prefix = "bzlws-344801b9b3105bd13e4b51ec9776f04bd5e01972",
25+
url = "https://github.com/zaucy/bzlws/archive/344801b9b3105bd13e4b51ec9776f04bd5e01972.zip",
2826
)
2927

3028
load("@bzlws//:repo.bzl", "bzlws_deps")
29+
3130
bzlws_deps()
3231

3332
http_archive(
3433
name = "rules_7zip",
34+
sha256 = "29ba984e2a7d48540faa839efaf09be4b880d211a93575e7ac87abffc12dbdea",
3535
strip_prefix = "rules_7zip-25d3b858a37580dbc1f1ced002e210be15012e2f",
3636
urls = ["https://github.com/zaucy/rules_7zip/archive/25d3b858a37580dbc1f1ced002e210be15012e2f.zip"],
37-
sha256 = "29ba984e2a7d48540faa839efaf09be4b880d211a93575e7ac87abffc12dbdea",
3837
)
3938

4039
load("@rules_7zip//:setup.bzl", "setup_7zip")
40+
4141
setup_7zip()
4242

4343
_nlohmann_json_build_file = """
@@ -54,9 +54,9 @@ cc_library(
5454

5555
http_archive(
5656
name = "nlohmann_json",
57-
url = "https://github.com/nlohmann/json/releases/download/v3.10.4/include.zip",
58-
sha256 = "62c585468054e2d8e7c2759c0d990fd339d13be988577699366fe195162d16cb",
5957
build_file_content = _nlohmann_json_build_file,
58+
sha256 = "62c585468054e2d8e7c2759c0d990fd339d13be988577699366fe195162d16cb",
59+
url = "https://github.com/nlohmann/json/releases/download/v3.10.4/include.zip",
6060
)
6161

6262
http_archive(
@@ -66,6 +66,7 @@ http_archive(
6666
)
6767

6868
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
69+
6970
node_repositories()
7071

7172
http_archive(
@@ -76,4 +77,18 @@ http_archive(
7677
)
7778

7879
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")
80+
7981
aspect_bazel_lib_dependencies()
82+
83+
http_archive(
84+
name = "rules_pkg",
85+
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
86+
urls = [
87+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
88+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
89+
],
90+
)
91+
92+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
93+
94+
rules_pkg_dependencies()

packages/BUILD.bazel

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
load("@bzlws//:index.bzl", "bzlws_copy")
1+
load("@bzlws//:index.bzl", "bzlws_copy", "bzlws_extract")
22

33
package(default_visibility = ["//visibility:public"])
44

5-
bzlws_copy(
5+
# bzlws_copy(
6+
# name = "copy_for_dev",
7+
# testonly = True,
8+
# srcs = ["//packages/com.seaube.ecsact:generators"],
9+
# out = "packages/com.seaube.ecsact/generators~.tar",
10+
# force = True,
11+
# metafile_path = "generators~/.copy_for_dev.yml",
12+
# visibility = ["//visibility:private"],
13+
# )
14+
15+
bzlws_extract(
616
name = "copy_for_dev",
7-
visibility = ["//visibility:private"],
817
testonly = True,
18+
srcs = ["//packages/com.seaube.ecsact:generators"],
19+
out = "packages/com.seaube.ecsact/generators~",
920
force = True,
10-
out = "packages/com.seaube.ecsact/generators~/{FILENAME}",
1121
metafile_path = "generators~/.copy_for_dev.yml",
12-
srcs = [
13-
"@ecsact//generator/csharp:cli",
14-
"@ecsact//generator/parser_info:cli",
15-
],
22+
visibility = ["//visibility:private"],
1623
)

packages/com.seaube.ecsact/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ crashlytics-build.properties
7171
/[Aa]ssets/[Ss]treamingAssets/aa/*
7272

7373
# Folder that stores codegen executables
74-
# /generators~
74+
/generators~
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
2-
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
1+
load(":pkg.bzl", "pkg_executable")
2+
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
33

4-
copy_to_directory(
5-
name = "generators~",
6-
replace_prefixes = {
7-
"generator/csharp/": "",
8-
"generator/parser_info/": "",
9-
},
10-
include_external_repositories = [
11-
"ecsact",
12-
],
13-
srcs = [
14-
"@ecsact//generator/csharp:cli",
15-
"@ecsact//generator/parser_info:cli",
16-
],
4+
pkg_executable(
5+
name = "ecsact_csharp_codegen_with_runfiles",
6+
bin = "@ecsact//generator/csharp:cli",
7+
path = "ecsact_csharp_codegen",
8+
)
9+
10+
pkg_executable(
11+
name = "ecsact_parser_info_codegen_with_runfiles",
12+
bin = "@ecsact//generator/parser_info:cli",
13+
path = "ecsact_parser_info_codegen",
1714
)
1815

19-
pkg_npm(
20-
name = "com.seaube.ecsact",
21-
package_name = "com.seaube.ecsact",
22-
deps = [":generators~"],
23-
srcs = glob(["**/*"]),
16+
pkg_executable(
17+
name = "ecsact_rtb_with_runfiles",
18+
bin = "@ecsact_rtb//cli:ecsact-rtb",
19+
path = "ecsact-rtb",
2420
)
2521

26-
alias(name = "pack", actual = "com.seaube.ecsact.pack")
27-
alias(name = "publish", actual = "com.seaube.ecsact.publish")
22+
pkg_tar(
23+
name = "generators",
24+
srcs = [
25+
":ecsact_csharp_codegen_with_runfiles",
26+
":ecsact_parser_info_codegen_with_runfiles",
27+
":ecsact_rtb_with_runfiles",
28+
],
29+
visibility = ["//visibility:public"],
30+
)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Ecsact.Editor {
5+
[CustomEditor(typeof(Ecsact.DefaultRunner))]
6+
public class DefaultRunnerEditor : UnityEditor.Editor {
7+
public override bool RequiresConstantRepaint() {
8+
return Application.isPlaying;
9+
}
10+
11+
public override void OnInspectorGUI() {
12+
var runner = target as DefaultRunner;
13+
var executionHeatStyle = new GUIStyle(EditorStyles.label);
14+
executionHeatStyle.normal.textColor = Color.green;
15+
16+
float deltaTimePc = 0f;
17+
if(runner.debugExecutionTimeMs > 0) {
18+
// 0.0 - 1.0 how much the execution time takes up from the delta time
19+
deltaTimePc =
20+
Time.deltaTime / ((float)runner.debugExecutionTimeMs) / 1000f;
21+
22+
if(deltaTimePc > 0.5) {
23+
executionHeatStyle.normal.textColor = Color.red;
24+
} else if(deltaTimePc > 0.2) {
25+
executionHeatStyle.normal.textColor = Color.yellow;
26+
}
27+
}
28+
29+
EditorGUILayout.LabelField(
30+
"Execution Count",
31+
$"{runner.debugExecutionCountTotal}"
32+
);
33+
EditorGUILayout.LabelField(
34+
"Execution Time",
35+
$"{runner.debugExecutionTimeMs}ms " +
36+
$"({deltaTimePc*100:0.0}% of delta time)",
37+
executionHeatStyle
38+
);
39+
}
40+
}
41+
}

packages/com.seaube.ecsact/Editor/DefaultRunnerEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
{
2-
"name": "Ecsact.Editor",
3-
"rootNamespace": "",
4-
"references": [
5-
"Ecsact",
6-
"Unity.EditorCoroutines.Editor"
7-
],
8-
"includePlatforms": [
9-
"Editor"
10-
],
11-
"excludePlatforms": [],
12-
"allowUnsafeCode": false,
13-
"overrideReferences": false,
14-
"precompiledReferences": [],
15-
"autoReferenced": true,
16-
"defineConstraints": [],
17-
"versionDefines": [],
18-
"noEngineReferences": false
19-
}
2+
"name": "Ecsact.Editor",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:6e7029456009ab94da19a8f93d5e3523",
6+
"GUID:478a2357cc57436488a56e564b08d223",
7+
"GUID:21b0c8d1703a94250bfac916590cea4f",
8+
"GUID:54cb1906aeb4e4264bc1d2aa3818a43f",
9+
"GUID:ea715009a4efd4c6cbc85be3ae097dd3",
10+
"GUID:23f3c6063e13e4fd9addce3606ff4e42",
11+
"GUID:7faa839a710e565409361b9f0c62a4da",
12+
"GUID:2cd956959600cec4a97cd312e2adbdbb"
13+
],
14+
"includePlatforms": [
15+
"Editor"
16+
],
17+
"excludePlatforms": [],
18+
"allowUnsafeCode": false,
19+
"overrideReferences": false,
20+
"precompiledReferences": [],
21+
"autoReferenced": true,
22+
"defineConstraints": [],
23+
"versionDefines": [],
24+
"noEngineReferences": false
25+
}

packages/com.seaube.ecsact/Editor/EcsactPackagesPostprocessor.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Diagnostics;
55
using System.Collections.Generic;
6+
using System.Linq;
67

78
public class EcsactPackagesPostprocessor : AssetPostprocessor {
89

@@ -59,6 +60,26 @@ static void OnPostprocessAllAssets
5960
}
6061
}
6162

63+
static void TryImportAssets
64+
( List<string> assets
65+
)
66+
{
67+
EditorApplication.delayCall += () => {
68+
if(!Progress.running) {
69+
try {
70+
AssetDatabase.StartAssetEditing();
71+
foreach(var asset in assets) {
72+
AssetDatabase.ImportAsset(asset);
73+
}
74+
} finally {
75+
AssetDatabase.StopAssetEditing();
76+
}
77+
} else {
78+
TryImportAssets(assets);
79+
}
80+
};
81+
}
82+
6283
static void RefreshEcsactCodegen
6384
( List<string> importedPkgs
6485
, List<string> deletedPkgs
@@ -70,7 +91,7 @@ static void RefreshEcsactCodegen
7091
);
7192

7293
var progressId = Progress.Start(
73-
"ECSACT Codegen",
94+
"Ecsact Codegen",
7495
"Generating C# files..."
7596
);
7697

@@ -97,19 +118,15 @@ static void RefreshEcsactCodegen
97118
UnityEngine.Debug.LogError(codegen.StandardError.ReadToEnd());
98119
Progress.Remove(progressId);
99120
} else {
100-
Progress.Report(progressId, 0.9f);
101-
102-
EditorApplication.delayCall += () => {
103-
foreach(var importedPkg in importedPkgs) {
104-
// Import newly created scripts
105-
AssetDatabase.ImportAsset(importedPkg + ".cs");
106-
}
107-
Progress.Remove(progressId);
108-
};
121+
Progress.Finish(progressId, Progress.Status.Succeeded);
122+
// Import newly created scripts
123+
// TryImportAssets(importedPkgs.Select(pkg => pkg + ".cs").ToList());
109124
}
110125
};
111126

112-
foreach(var (pkg, pkgPath) in FindEcsactPackages()) {
127+
var packages = FindEcsactPackages().ToList();
128+
129+
foreach(var (pkg, pkgPath) in packages) {
113130
codegen.StartInfo.Arguments += pkgPath + " ";
114131
}
115132

@@ -119,6 +136,10 @@ static void RefreshEcsactCodegen
119136
foreach(var plugin in GetCodegenPlugins()) {
120137
// TODO: Custom codegen plugins
121138
}
139+
140+
EcsactRuntimeBuilder.Build(new EcsactRuntimeBuilder.Options{
141+
ecsactFiles = packages.Select(item => item.Item2).ToList(),
142+
});
122143
}
123144

124145
static IEnumerable<EcsactCodegenPlugin> GetCodegenPlugins() {

0 commit comments

Comments
 (0)