Skip to content

Commit

Permalink
Attempt to fix Windows issue
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jul 24, 2024
1 parent 5a0d6bc commit 75830d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module(
)

bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.6")

bazel_dep(name = "aspect_bazel_lib", version = "1.34.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "platforms", version = "0.0.6", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.4.0", dev_dependency = True)
bazel_dep(name = "stardoc", dev_dependency = True)
git_override(
Expand Down
25 changes: 19 additions & 6 deletions with_cfg/private/frontend.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,30 @@ def get_frontend(*, executable, test):
return _frontend_default

def _frontend_impl(ctx):
# type: (ctx) -> None
target = ctx.attr.exports

original_executable = target[FrontendInfo].executable
dirname, separator, basename = ctx.label.name.rpartition("/")
executable_basename = original_executable.basename
executable = ctx.actions.declare_file(dirname + separator + basename + "/" + executable_basename)
executable = ctx.actions.declare_file(ctx.label.name + "/" + executable_basename)

additional_runfiles = [executable]
if CcInfo in target and ctx.target_platform_has_constraint(ctx.attr._windows[platform_common.ConstraintValueInfo]):
dlls_to_relocate = [
f
for f in target[DefaultInfo].default_runfiles.files.to_list()
if f.path.endswith(".dll") and f.dirname != executable.dirname
]
for dll in dlls_to_relocate:
out_dll = ctx.actions.declare_file(dll.basename, sibling = executable)
ctx.actions.symlink(output = out_dll, target_file = dll)
additional_runfiles.append(out_dll)

print(additional_runfiles)

# TODO: If this is a copy rather than a symlink, runfiles discovery will not work correctly.
# Fix this by using a wrapper script rather than a symlink.
ctx.actions.symlink(output = executable, target_file = original_executable)
data_runfiles = ctx.runfiles([executable]).merge(target[DefaultInfo].data_runfiles)
default_runfiles = ctx.runfiles([executable]).merge(target[DefaultInfo].default_runfiles)
data_runfiles = ctx.runfiles(additional_runfiles).merge(target[DefaultInfo].data_runfiles)
default_runfiles = ctx.runfiles(additional_runfiles).merge(target[DefaultInfo].default_runfiles)

run_environment_info = _clean_run_environment_info(
target[FrontendInfo].run_environment_info,
Expand Down Expand Up @@ -79,6 +91,7 @@ _frontend_attrs = {
mandatory = True,
providers = [FrontendInfo],
),
"_windows": attr.label(default = "@platforms//os:windows"),
}

_frontend_test_attrs = {
Expand Down

0 comments on commit 75830d0

Please sign in to comment.