[source]
git = "https://gitlab.redox-os.org/redox-os/servo.git"
branch = "redox"

[build]
template = "custom"
dependencies = [
    "expat",
    "fontconfig",
    "freetype2",
    "libpng",
    "mesa",
    "zlib",
]
dev-dependencies = [
    "llvm21.dev",
    "host:libarchive",  # workaround for cmake error
]
script = """
DYNAMIC_INIT

cp -v "${COOKBOOK_RECIPE}/.servobuild" "${COOKBOOK_SOURCE}/.servobuild"

# jemalloc specific configuration
export JEMALLOC_SYS_WITH_LG_PAGE=16
export TARGET_CC="$CC"
export TARGET_CXX="$CXX"
export TARGET_AR="$AR"

# pkg-config crate can only recognize one path to pkgconfig
export PKG_CONFIG_PATH_x86_64_unknown_redox="${COOKBOOK_SYSROOT}/lib/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_redox="${COOKBOOK_SYSROOT}/lib/pkgconfig"
# rsync -a -v ${COOKBOOK_SYSROOT}/usr/share/pkgconfig/*.pc ${COOKBOOK_SYSROOT}/lib/pkgconfig/

#TODO: mozjs-sys and mozangle uses clang, it won't know our prefix C libraries, so here's the workaround
PREFIX_INCLUDE="$COOKBOOK_HOST_SYSROOT/$TARGET/include"
export CLANGFLAGS="-I $PREFIX_INCLUDE/c++/13.2.0 -I $PREFIX_INCLUDE/c++/13.2.0/$TARGET -I $PREFIX_INCLUDE/c++/13.2.0/backward -I $PREFIX_INCLUDE"

#Mozjs specifics
unset CC_WRAPPER
export CARGO_MAKEFLAGS="-j $COOKBOOK_MAKE_JOBS" CCACHE="sccache"

COOKBOOK_CARGO_PATH="ports/servoshell" cookbook_cargo

# resources packaging
mkdir -p ${COOKBOOK_STAGE}/usr/lib/servo/bin
mv ${COOKBOOK_STAGE}/usr/bin/servo ${COOKBOOK_STAGE}/usr/lib/servo/bin/
ln -s ../lib/servo/bin/servo ${COOKBOOK_STAGE}/usr/bin/servo
rsync -a -v ${COOKBOOK_SOURCE}/resources ${COOKBOOK_STAGE}/usr/lib/servo/
"""

[package]
dependencies = [
    "mesa"
]
