Skip to content

Commit 695ea5c

Browse files
committed
System toolchain
1 parent 8933c29 commit 695ea5c

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

ecsact/private/toolchains_repo.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ load(":defs.bzl", "resolved_toolchain")
6868
6969
resolved_toolchain(name = "resolved_toolchain", visibility = ["//visibility:public"])
7070
71+
toolchain(
72+
name = "system_toolchain",
73+
toolchain = "@{user_repository_name}//:ecsact_toolchain",
74+
toolchain_type = "@rules_ecsact//ecsact:toolchain_type",
75+
)
7176
"""
7277

7378
_PLATFORM_BUILD_CONTENT = """
@@ -84,7 +89,9 @@ toolchain(
8489
def _toolchains_repo_impl(rctx):
8590
rctx.file("defs.bzl", _STARLARK_CONTENT)
8691

87-
build_content = _BUILD_CONTENT
92+
build_content = _BUILD_CONTENT.format(
93+
user_repository_name = rctx.attr.user_repository_name,
94+
)
8895

8996
for [platform, meta] in PLATFORMS.items():
9097
build_content += _PLATFORM_BUILD_CONTENT.format(

ecsact/repositories.bzl

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ def _ecsact_repo_impl(rctx):
7171
_download_repo(rctx, rctx.attr.platform)
7272

7373
_HOST_BUILD_CONTENT = """
74+
load("@rules_ecsact//ecsact:toolchain.bzl", "ecsact_toolchain")
75+
76+
package(default_visibility = ["//visibility:public"])
77+
78+
ecsact_toolchain(
79+
name = "ecsact_toolchain",
80+
target_tool_path = "{target_tool_path}",
81+
)
7482
"""
7583

7684
_CODEGEN_BUILD_CONTENT = """
@@ -109,8 +117,40 @@ ecsact_codegen_plugin(
109117
)
110118
"""
111119

120+
_FIND_ECSACT_SDK_PWSH = """
121+
$EcsactSdkInfo = Get-AppPackage EcsactSdk
122+
if($EcsactSdkInfo) {
123+
echo $EcsactSdkInfo.InstallLocation
124+
}
125+
"""
126+
112127
def _ecsact_host_repo_impl(rctx):
113-
rctx.file("BUILD.bazel", _HOST_BUILD_CONTENT)
128+
is_windows = rctx.os.name.startswith("windows")
129+
exe_extension = ""
130+
if is_windows:
131+
exe_extension = ".exe"
132+
ecsact_executable_name = "ecsact" + exe_extension
133+
134+
ecsact_path = rctx.which(ecsact_executable_name)
135+
136+
if ecsact_path == None and is_windows:
137+
pwsh = rctx.which("pwsh.exe")
138+
if pwsh == None:
139+
fail("Cannot find pwsh.exe")
140+
rctx.file("FindEcsactSdk.ps1", _FIND_ECSACT_SDK_PWSH)
141+
exec_result = rctx.execute([pwsh, "FindEcsactSdk.ps1"])
142+
ecsact_sdk_install_dir = exec_result.stdout
143+
if ecsact_sdk_install_dir:
144+
ecsact_sdk_install_dir = ecsact_sdk_install_dir.replace("\\", "/").strip()
145+
ecsact_path = ecsact_sdk_install_dir + "/bin/ecsact.exe"
146+
147+
if ecsact_path == None:
148+
rctx.file("BUILD.bazel", "")
149+
else:
150+
rctx.file("BUILD.bazel", _HOST_BUILD_CONTENT.format(
151+
target_tool_path = ecsact_path,
152+
))
153+
114154
rctx.file("codegen_plugins/BUILD.bazel", _CODEGEN_BUILD_CONTENT)
115155

116156
ecsact_repository = repository_rule(

0 commit comments

Comments
 (0)