From b4ff17be88820667fd85fb37283e0e5d06130087 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 26 Jun 2024 14:00:42 +0100 Subject: [PATCH 1/2] fix(entrypoint): assimilate on Linux If a Linux user has Wine installed with the `binfmt_misc` registration, an APE binary is picked up and ran under the Wine runtime. Normally, this does not occur, as we force execution under the launcher. However, Python `sys.executable` will return the original binary so any Python script that uses `sys.executable` with `subprocess` will unexpectedly run under Wine. Assimilating the binary on Linux avoids this situation. In all other cases we can symlink to the binary. --- ape/entrypoint/repository.bzl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/ape/entrypoint/repository.bzl b/ape/entrypoint/repository.bzl index 020f83ce..f09ec66c 100644 --- a/ape/entrypoint/repository.bzl +++ b/ape/entrypoint/repository.bzl @@ -13,6 +13,13 @@ ATTRS = { cfg = "exec", default = "@launcher//:ape", ), + "assimilate": attr.label( + doc = "The assimilation APE binary.", + allow_single_file = True, + executable = True, + cfg = "exec", + default = "@cosmos-assimilate//:assimilate", + ), "binary": attr.label( doc = "The αcτµαlly pδrταblε εxεcµταblε binary.", allow_single_file = True, @@ -31,13 +38,19 @@ ATTRS = { } def implementation(rctx): - if "windows" in rctx.os.name: + if rctx.os.name != "linux": rctx.symlink(rctx.attr.binary, "entrypoint") else: - rctx.template("entrypoint", rctx.attr.posix, { - "{{launcher}}": str(rctx.path(rctx.attr.launcher)), - "{{binary}}": str(rctx.path(rctx.attr.binary)), - }, executable = True) + cmd = ( + rctx.attr.launcher, + rctx.path(rctx.attr.assimilate), + "-o", + "entrypoint", + rctx.path(rctx.attr.binary), + ) + result = rctx.execute(cmd) + if result.return_code != 0: + fail("Failed to assimilate: {}".format(cmd)) rctx.template("BUILD.bazel", rctx.attr.build, { "{{exports}}": repr(["entrypoint"]), -- GitLab From 699fcb6c036b94a3505d4231ee522daafbb4391d Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 26 Jun 2024 14:01:58 +0100 Subject: [PATCH 2/2] fix(entrypoint): add `local = True` This rule only depends on local data so can be marked as such. --- ape/entrypoint/repository.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/ape/entrypoint/repository.bzl b/ape/entrypoint/repository.bzl index f09ec66c..4696b855 100644 --- a/ape/entrypoint/repository.bzl +++ b/ape/entrypoint/repository.bzl @@ -61,4 +61,5 @@ entrypoint = repository_rule( attrs = ATTRS, implementation = implementation, configure = True, + local = True, ) -- GitLab