# -*- 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           cmake 1.1
PortGroup           github 1.0

# SimSIMD was renamed NumKong in 7.0.0 and its API replaced; this port keeps
# the last 6.x release for software still calling simsimd_*.
github.setup        ashvardanian NumKong 6.5.16 v
github.tarball_from archive
name                simsimd
revision            0

categories          devel math
license             Apache-2
maintainers         {@jrjsmrtn gmail.com:jrjsmrtn} openmaintainer

description         SIMD-accelerated vector similarity kernels, SimSIMD 6.x API

long_description    SimSIMD provides SIMD-accelerated distance and similarity \
                    kernels, such as cosine, inner product and Euclidean \
                    distances, for mixed-precision vectors on Arm and x86, \
                    with runtime dispatch to the best instruction set. \
                    Version 7 continues as NumKong with a different API.

checksums           rmd160  62308d53f8bec1c5a1bc3d5b84acf34a5af2d47c \
                    sha256  3aafa5a5e51b0959b2296ff575fa34bb42f4dac9578c6a52dd613f98fc4846fb \
                    size    228130

compiler.c_standard 2023
compiler.cxx_standard 2017
# MacPorts selects only a C17 compiler for 2023; CMake needs Apple clang
# 11.0.3 for C23.
compiler.blacklist-append \
                    {clang < 1103}

# The headers use __bfloat16 with any x86 clang, which declares it only with
# AVX512-BF16: https://github.com/ashvardanian/NumKong/issues/356
patchfiles          patch-types-bfloat16.diff

configure.args-append \
                    -DSIMSIMD_BUILD_SHARED=ON \
                    -DSIMSIMD_BUILD_TESTS=ON

# The generic top-level modulemap is only for Swift; numkong's port drops its
# own for the same reason.
post-destroot {
    delete ${destroot}${prefix}/include/module.modulemap
}

# Compile-time and run-time dispatch builds, which assert that both detect the
# same instruction sets. Those predefine the native-type settings, so also
# include the headers as a consumer would, from C and C++.
test.run            yes
test {
    foreach t {simsimd_test_compile_time simsimd_test_run_time} {
        system -W ${build.dir} ./${t}
    }
    set fd [open ${workpath}/consumer.c w]
    puts ${fd} "#include <simsimd/simsimd.h>\nint main(void) { return 0; }"
    close ${fd}
    file copy -force ${workpath}/consumer.c ${workpath}/consumer.cpp
    system -W ${workpath} "${configure.cc} -std=c11 -I${worksrcpath}/include consumer.c -o consumer-c"
    system -W ${workpath} "${configure.cxx} -std=c++17 -I${worksrcpath}/include consumer.cpp -o consumer-cxx"
}

# The 6.x tags sit behind the 7.x ones on GitHub's tags page.
github.livecheck.regex {(6\.[0-9.]+)}
livecheck.url       ${github.homepage}/tags?after=v7.0.0
