# -*- 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           zig_toolchain 1.0

name                zig

categories          lang
license             MIT
maintainers         nomaintainer

homepage            https://ziglang.org/

description         Zig programming language

long_description    \
    Zig is a general-purpose programming language designed for robustness, \
    optimality, and maintainability. This port provides zig and the Zig \
    standard library for the release series MacPorts currently offers. It \
    builds nothing of its own: it depends on that versioned toolchain and \
    links to it, so installing a particular series alongside is a matter of \
    installing zig-0.NN directly.

# This port builds nothing. It provides `zig` for the series zig_toolchain
# names as current, by depending on that toolchain and linking to its command.
# Which series that is has moved out of this Portfile so that `zig` cannot come
# to disagree with the toolchains it is built from.
set zig_series      [zig_toolchain.current_series]

# The version is the series, not a patch release. The wrapper's content -- two
# symlinks -- does not change when the toolchain it points at gets a patch
# update, so there is nothing here to re-version and nothing to fall out of
# step with the toolchain Portfiles.
#
# epoch, because 0.16 sorts below the 0.16.0 this port carried when it built
# the compiler itself, and an upgrade must not look like a downgrade.
epoch               1
version             ${zig_series}
revision            0

platforms           "darwin >= [zig_toolchain.min_darwin ${zig_series}]"

# Two symlinks, the same on every architecture.
supported_archs     noarch

depends_lib         port:zig-${zig_series}

use_configure       no

# Nothing to fetch, unpack or compile: the toolchain this links to has already
# done all of it.
distfiles
fetch               {}
extract             {}
build               {}

destroot {
    # zig resolves the path of its own executable before looking for its lib
    # directory, so pointing at the versioned command is enough: it lands in
    # that toolchain's own libexec tree.
    xinstall -d ${destroot}${prefix}/bin
    ln -s zig-${zig_series} ${destroot}${prefix}/bin/zig

    # ${prefix}/lib/zig was this port's own lib directory before it became a
    # wrapper, and is referenced by anything with ZIG_LIB_DIR set by hand or a
    # zls configuration naming it. The toolchain does not need it, so this is
    # purely so that the old path keeps working.
    xinstall -d ${destroot}${prefix}/lib
    ln -s ../libexec/zig-${zig_series}/lib/zig ${destroot}${prefix}/lib/zig
}

notes "
    Installed as a link to zig-${zig_series}. To build against a particular\
    Zig release series, depend on that series' port directly: it installs\
    alongside this one as zig-0.NN.
"

livecheck.type      none
