build-style/cargo.sh: add

This commit is contained in:
Rasmus Thomsen 2018-09-16 21:39:23 +02:00 committed by Enno Boland
parent 17eda45988
commit 0318d0385a
3 changed files with 49 additions and 0 deletions

View File

@ -734,6 +734,10 @@ The current list of available `build_style` scripts is the following:
`do_configure()`, `do_build()`, etc., and may overwrite default `do_fetch()` and
`do_extract()` that fetch and extract files defined in `distfiles` variable.
- `cargo` For packages written in rust that use Cargo for building.
Configuration arguments (such as `--features`) can be defined in the variable
`configure_args` and are passed to cargo during `do_build`.
- `cmake` For packages that use the CMake build system, configuration arguments
can be passed in via `configure_args`. The `cmake_builddir` variable may be
defined to specify the directory for building under `build_wrksrc` instead of

View File

@ -0,0 +1,35 @@
#
# This helper is for building rust projects which use cargo for building
#
do_configure() {
mkdir -p .cargo
# respect makejobs, do cross stuff
cat > .cargo/config <<EOF
[build]
jobs = ${makejobs#*j}
target = "${RUST_TARGET}"
[target.${RUST_TARGET}]
linker = "${CC}"
EOF
}
do_build() {
: ${make_cmd:=cargo}
${make_cmd} build --release ${configure_args}
}
do_check() {
: ${make_cmd:=cargo}
${make_cmd} test --release ${make_check_args}
}
do_install() {
: ${make_cmd:=cargo}
${make_cmd} install --root="${DESTDIR}/usr" ${make_install_args}
rm "${DESTDIR}"/usr/.crates.toml
}

View File

@ -0,0 +1,10 @@
hostmakedepends+=" cargo"
if [ "$CROSS_BUILD" ]; then
makedepends+=" rust"
fi
# Use the config we set in do_configure
export CARGO_HOME="$wrksrc/.cargo"
export PKG_CONFIG_ALLOW_CROSS=1