Skip to content

Commit c1a963d

Browse files
committed
Define the type of artifact to be produced by cargo.
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 <[email protected]>
1 parent 2677e11 commit c1a963d

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

templates/lib/before_deploy.sh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ PKG_NAME="{{PKG_NAME}}"
55
set -ex
66

77
main() {
8-
local src=$(pwd) \
9-
stage \
10-
linking_args
8+
local src=$(pwd) stage
119

1210
case $TRAVIS_OS_NAME in
1311
linux)
@@ -20,17 +18,13 @@ main() {
2018

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

23-
# TODO: combine with -C lto
24-
case $TYPE in
25-
static)
26-
linking_args="--crate-type staticlib"
27-
;;
28-
*)
29-
linking_args="--crate-type cdylib"
30-
;;
31-
esac
21+
if [[ "$TYPE" == "static" ]]; then
22+
cargo crate-type static
23+
else
24+
cargo crate-type dynamic
25+
fi
3226

33-
cross rustc --lib --target $TARGET --release -- $linking_args
27+
cross rustc --lib --target $TARGET --release -- -C lto
3428

3529
case $TYPE-$TRAVIS_OS_NAME in
3630
static-*)

templates/lib/install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ main() {
4646
# Install test dependencies
4747
rustup component add rustfmt-preview
4848
rustup component add clippy-preview
49+
50+
# For defining the type of lib to produce: dynamic OR static
51+
cargo install --force cargo-crate-type
4952
}
5053

5154
main

0 commit comments

Comments
 (0)