# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0

github.setup        apple container 1.6.1
github.tarball_from archive
revision            0
platforms           {macosx >= 25}
supported_archs     arm64
categories          devel
license             Apache-2
maintainers         {i0ntempest @i0ntempest} openmaintainer

description         A tool to create and run Linux containers on your Mac
long_description    container is a tool that you can use to create and run Linux \
                    containers as lightweight virtual machines on your Mac. \
                    The tool consumes and produces OCI-compatible container images, \
                    so you can pull and run images from any standard container \
                    registry. You can push images that you build to those registries \
                    as well, and run the images in any other OCI-compatible application.

checksums           rmd160  156550b932c5451c6b8d9ccf465b05fc656f2cd6 \
                    sha256  29c95aee960d5346452ef314fd3fdcb527c217ea4298a46bdb315221397f28b5 \
                    size    1123225

if {${os.platform} eq "darwin" && (${os.major} < 25 || ${os.arch} ne "arm")} {
    known_fail yes
    pre-fetch {
        ui_error "${name} requires macOS 26 or later on Apple Silicon (arm64)."
        return -code error "incompatible macOS version or architecture"
    }
}

use_configure       no
use_parallel_build  no
use_xcode           yes
installs_libs       no

pre-configure {
    set git-commit [exec curl -fsSL \
                        -H "Accept: application/vnd.github.sha" \
                        https://api.github.com/repos/${github.author}/${github.project}/commits/${version} | \
                        cut -c1-7]

    build.pre_args-append \
                    GIT_COMMIT=${git-commit}
}

build.target        build
# Disable the swift sandbox since the port build already runs in a sandbox
build.pre_args-append \
                    BUILD_CONFIGURATION=release \
                    SWIFT_CONFIGURATION="--disable-sandbox --cache-path ${workpath}/.swiftpm/cache --security-path ${workpath}/.swiftpm/security --config-path ${workpath}/.swiftpm/config -Xswiftc -enable-testing" \
                    RELEASE_VERSION=${version} \
                    ${build.target}

destroot.target     install
destroot.pre_args   BUILD_CONFIGURATION=release \
                    DEST_DIR="${destroot}${prefix}/" \
                    RELEASE_VERSION=${version} \
                    SUDO= \
                    ${destroot.target}

post-destroot {
    # Remove the unnecessary scripts
    file delete -force ${destroot}${prefix}/bin/uninstall-container.sh ${destroot}${prefix}/bin/update-container.sh
}
