# -*- 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
PortGroup           git_archive 1.0

github.setup        apple container 1.7.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  cf4b08992e9eee76af386112250c875f4f7b002a \
                    sha256  ef497b524624048ee45d57b0f7fdd675d6d420fcb30ab4a039779d752d9dea66 \
                    size    1262845

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-build {
    build.pre_args-append \
                    GIT_COMMIT=[git_archive::short_commit_id]
}

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
}
