Skip to content

Commit

Permalink
Define the type of artifact to be produced by cargo.
Browse files Browse the repository at this point in the history
s command `cargo` subcommand is exclusively intended to be used to help
with [working arround](rust-lang/rust#51009)
how crate types are defined, in order to help with cross-platform
builds.

It is currently [not possible](rust-lang/cargo#6160) to define a
single `crate-type` override on `cargo build`, which causes libs
intended to be used on other languages to compile more than one type of
crate.

This commit adds a dependency on this [new CLI app](https://github.com/bltavares/cargo-crate-type) to be able to workaround the limitations of Cargo.

We are now able to enable the `-C lto` optimization again, as we will
only compile a single type of artifact

Signed-off-by: Bruno Tavares <connect+github@bltavares.com>
  • Loading branch information
bltavares committed Nov 18, 2018
1 parent 2677e11 commit c1a963d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
20 changes: 7 additions & 13 deletions templates/lib/before_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ PKG_NAME="{{PKG_NAME}}"
set -ex

main() {
local src=$(pwd) \
stage \
linking_args
local src=$(pwd) stage

case $TRAVIS_OS_NAME in
linux)
Expand All @@ -20,17 +18,13 @@ main() {

test -f Cargo.lock || cargo generate-lockfile

# TODO: combine with -C lto
case $TYPE in
static)
linking_args="--crate-type staticlib"
;;
*)
linking_args="--crate-type cdylib"
;;
esac
if [[ "$TYPE" == "static" ]]; then
cargo crate-type static
else
cargo crate-type dynamic
fi

cross rustc --lib --target $TARGET --release -- $linking_args
cross rustc --lib --target $TARGET --release -- -C lto

case $TYPE-$TRAVIS_OS_NAME in
static-*)
Expand Down
3 changes: 3 additions & 0 deletions templates/lib/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ main() {
# Install test dependencies
rustup component add rustfmt-preview
rustup component add clippy-preview

# For defining the type of lib to produce: dynamic OR static
cargo install --force cargo-crate-type
}

main

0 comments on commit c1a963d

Please sign in to comment.