# 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

name = "SPIRV_Cross"
version = v"2021.01.15"

# Collection of sources required to complete build
sources = [
    GitSource("https://github.com/KhronosGroup/SPIRV-Cross.git", "9acb9ec31f5a8ef80ea6b994bb77be787b08d3d1")
]

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

install_license LICENSE

CMAKE_FLAGS=()
CMAKE_FLAGS+=(-DCMAKE_BUILD_TYPE=Release)
CMAKE_FLAGS+=(-DCMAKE_INSTALL_PREFIX=${prefix})
CMAKE_FLAGS+=(-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN})
CMAKE_FLAGS+=(-DCMAKE_CROSSCOMPILING:BOOL=ON)
CMAKE_FLAGS+=(-DBUILD_SHARED_LIBS=ON)
CMAKE_FLAGS+=(-DSPIRV_CROSS_SHARED=ON)

mkdir build && cd build

cmake  ${CMAKE_FLAGS[@]} ..
make -j${nproc}
make install
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = expand_cxxstring_abis(supported_platforms()) # build on all supported platforms


# The products that we will ensure are always built
products = [
    LibraryProduct("libspirv-cross-c-shared", :libspirv_cross),
    ExecutableProduct("spirv-cross", :spirv_cross)
]

# Dependencies that must be installed before this package can be built
dependencies = Dependency[
]

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