Skip to content

Commit

Permalink
fix: cross build on darwin (#4331)
Browse files Browse the repository at this point in the history
Signed-off-by: Yue Yang <g1enyy0ung@gmail.com>
  • Loading branch information
g1eny0ung committed Feb 2, 2024
1 parent a13bfc8 commit 3855098
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions build/build_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def main():
"build",
"--load",
"--platform",
os.getenv("TARGET_PLATFORM")]
f"linux/{os.getenv('TARGET_PLATFORM')}"]
else:
# This branch is split to avoid to use `buildx`, as `buildx` is
# not supported on some CI environment
Expand All @@ -139,7 +139,7 @@ def main():
pass_env_to_build_arg(cmd, env_key)

target_platform = utils.get_target_platform()
cmd += ["--build-arg", f"TARGET_PLATFORM={target_platform}"]
cmd += ["--build-arg", f"TARGET_PLATFORM={target_platform.platform}"]
cmd += ["-t", image_full_name, args.path[0]]
else:
cmd = ["docker", "pull", image_full_name]
Expand Down
12 changes: 4 additions & 8 deletions build/get_env_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,12 @@ def main():
cmd += ["--user", f"{os.getuid()}:{os.getgid()}"]

target_platform = utils.get_target_platform()
# if the environment variable is not set, don't pass `--platform` argument,
# If the environment variable is not set, don't pass `--platform` argument,
# as it's not supported on some docker build environment.
if os.getenv("TARGET_PLATFORM") is not None and os.getenv(
"TARGET_PLATFORM") != "":
cmd += ["--platform", f"linux/{os.getenv('TARGET_PLATFORM')}"]
if target_platform.from_env:
cmd += ["--platform", f"linux/{target_platform.platform}"]
else:
cmd += ["--env", f"TARGET_PLATFORM={target_platform}"]

if target_platform == "arm64":
cmd += ["--env", "ETCD_UNSUPPORTED_ARCH=arm64"]
cmd += ["--env", f"TARGET_PLATFORM={target_platform.platform}"]

if os.getenv("GO_BUILD_CACHE") is not None and os.getenv(
"GO_BUILD_CACHE") != "":
Expand Down
14 changes: 8 additions & 6 deletions build/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import os
import sys
from collections import namedtuple


def underscore_uppercase(name):
Expand All @@ -33,21 +34,22 @@ def get_target_platform():
get the target platform according to the `TARGET_PLATFORM` variable or the
`uname` syscall
"""
Platform = namedtuple('Platform', ['platform', 'from_env'])

if os.getenv("TARGET_PLATFORM") is not None and os.getenv("TARGET_PLATFORM") != "":
return os.getenv("TARGET_PLATFORM")
return Platform(os.getenv("TARGET_PLATFORM"), True)

machine = os.uname().machine
if machine == "x86_64":
return "amd64"
return Platform("amd64", False)

if machine == "amd64":
return "amd64"
return Platform("amd64", False)

if machine == "arm64":
return "arm64"
return Platform("arm64", False)

if machine == "aarch64":
return "arm64"
return Platform("arm64", False)

sys.exit("Please run this script on amd64 or arm64 machine")
sys.exit("Please run this script on amd64 or arm64 machines.")

0 comments on commit 3855098

Please sign in to comment.