Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ group "test" {
"test-verify",
"test-clang",
"test-go",
"test-cargo"
"test-cargo",
"test-macports"
]
}

Expand Down Expand Up @@ -97,6 +98,11 @@ target "test-cargo" {
target = "test-cargo"
}

target "test-macports" {
inherits = ["test-base"]
target = "test-macports"
}

group "validate" {
targets = ["shfmt-validate", "shellcheck"]
}
Expand Down
8 changes: 8 additions & 0 deletions src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ COPY --from=build /out/ /usr/bin/

FROM --platform=$BUILDPLATFORM tonistiigi/bats-assert AS bats-assert

# osxcross for usage with macports: https://github.com/tpoechtrager/osxcross/blob/master/README.MACPORTS.md
FROM --platform=$BUILDPLATFORM crazymax/osxcross:13.1 AS osxcross

FROM ${TEST_BASE_IMAGE} AS test-base-alpine
RUN --mount=type=cache,target=/pkg-cache \
ln -s /pkg-cache /etc/apk/cache && \
Expand Down Expand Up @@ -92,6 +95,11 @@ FROM test-base-fixtures AS test-cargo
COPY test-cargo.bats test_helper.bash ./
RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-cargo.bats

FROM test-base AS test-macports
COPY test-macports.bats test_helper.bash ./
ENV PATH="/osxcross/bin:$PATH"
ENV OSXCROSS_TARGET_DIR=/osxcross
RUN --mount=type=cache,target=/pkg-cache,sharing=locked --mount=from=osxcross,source=/osxcross,target=/osxcross,rw ./test-macports.bats

# these targets can be overwritten with build contexts
FROM scratch AS sdk-extras
Expand Down
15 changes: 15 additions & 0 deletions src/test-macports.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bats

load 'assert'
load 'test_helper'

@test "install" {
add openssl wget
assert_success

export TARGETOS=darwin
run xx-macports --static install jq
assert_success
assert_output --partial "installed jq"
run test -e "${OSXCROSS_TARGET_DIR}/macports/pkgs/opt/local/bin/jq"
}
69 changes: 69 additions & 0 deletions src/xx-macports
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env sh

set -e

for l in $(xx-info env); do
export "${l?}"
done

if [ "$(xx-info os)" != "darwin" ]; then
echo >&2 "WARN: skipping macports on $(xx-info os)"
exit 0
fi

if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
export MACOSX_DEPLOYMENT_TARGET=10.10
if [ "$(xx-info march)" = "arm64" ]; then
export MACOSX_DEPLOYMENT_TARGET=11.2
fi
fi

packages=
parsed=
n=$#
for p in "$@"; do
if [ $# = $n ]; then set --; fi
arg=
case "$p" in
-*)
arg="$p"
;;
"install" | "search")
parsed=1
arg="$p"
;;
*)
if [ -n "$parsed" ]; then
if [ -z "${packages}" ]; then
packages="$p"
else
packages="${packages} ${p}"
fi
else
arg="$p"
fi
;;
esac
if [ -n "$arg" ]; then
set -- "$@" "$arg"
fi
done

for p in ${packages}; do
n=${p}
set -- "$@" "$n"
done

flags=""
if [ "$(xx-info march)" = "arm64" ]; then
flags="--arm64"
fi

if ! command -v "osxcross-macports" >/dev/null 2>/dev/null; then
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current changes osxcross needs to be mounted in the Dockerfile but we could just fork https://github.com/tpoechtrager/osxcross/blob/master/tools/osxcross-macports. It just requires wget to download packages so should be fine as we need it for also prebuilt ld binaries. More info: https://github.com/tpoechtrager/osxcross/blob/master/README.MACPORTS.md

@tonistiigi WDYT?

echo >&2 'WARN: osxcross-macports command not found. Is osxcross installed?'
exit 0
fi

echo 1 | osxcross-macports select-mirror >/dev/null 2>&1 || true

exec osxcross-macports $flags "$@"