# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using BinaryBuilder, Pkg

# See https://github.com/JuliaLang/Pkg.jl/issues/2942
# Once this Pkg issue is resolved, this must be removed
uuid = Base.UUID("a83860b7-747b-57cf-bf1f-3e79990d037f")
delete!(Pkg.Types.get_last_stdlibs(v"1.6.3"), uuid)

name = "DACE"
version = v"0.7.1"

# Collection of sources required to build DACE
sources = [
    GitSource("https://github.com/a-ev/dace.git", "bc26842ae5c6936f9e008a2dc0d9227a8d982acc"),
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/dace

cmake . -B build \
    -DJulia_PREFIX=${prefix} \
    -DCMAKE_INSTALL_PREFIX=${prefix} \
    -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
    -DCMAKE_FIND_ROOT_PATH=${prefix} \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_PTHREAD=ON \
    -DWITH_ALGEBRAICMATRIX=ON \
    -DCUSTOM_EXIT=ON \
    -DWITH_JULIA=ON \
    -DWITH_EIGEN=ON

VERBOSE=ON cmake --build build --config Release --target install -- -j${nproc}

install_license {LICENSE,NOTICE}
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
include("../../L/libjulia/common.jl")
platforms = vcat(libjulia_platforms.(julia_versions)...)
platforms = expand_cxxstring_abis(platforms)

# The products that we will ensure are always built
products = [
    LibraryProduct("libdace", :libdace),
]

# Dependencies that must be installed before this package can be built
dependencies = [
    BuildDependency(PackageSpec(name="libjulia_jll")),
    BuildDependency("Eigen_jll"),
    Dependency("libcxxwrap_julia_jll"; compat="~0.14.2"),
]

# Build the tarballs, and possibly a `build.jl` as well.
build_tarballs(
    ARGS,
    name,
    version,
    sources,
    script,
    platforms,
    products,
    dependencies;
    julia_compat="1.6",
    preferred_gcc_version=v"12",
)

# rebuild trigger: 0
