Skip to content

Commit 2677e11

Browse files
committed
Improve lib template on Travis
This commit contains changes on the generated lib template to build cross-platform libs. With this changes, I was able to setup a [Travis] build with GitHub [Releases] of a cross-platform lib. It is not possible yet to build a different crate type only using command line args. It requires a modification on `Cargo.toml` to include new types of library outputs. I've already opened an issue on [cargo](rust-lang/cargo#6160) to see what should be the case here. Meanwhile, lib authors must change `Cargo.toml` and include the extra `crate-type` attribute with all the libs. Sadly, this also means that `LTO` optimisation is not available if the lib uses `lib` or `rlib` attributes. To avoid modifying the `Cargo.toml`, the sugestion would be that on a future PR we could add to the deploy script a modification on the `Cargo.toml` manifest to include the corresponding crate-type, and only such crate type for that target. This means we would be able to bring LTO and output smaller libs. Realated to: - yoshuawuyts#11 [Travis]: https://travis-ci.org/bltavares/rust-over-jna-example/builds/439439854 [Releases]: https://github.com/bltavares/rust-over-jna-example/releases/tag/initial Signed-off-by: Bruno Tavares <connect+github@bltavares.com>
1 parent 48fa6fc commit 2677e11

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

templates/lib/before_deploy.sh

+31-9
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,43 @@ set -ex
66

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

1112
case $TRAVIS_OS_NAME in
12-
linux)
13-
stage=$(mktemp -d)
14-
;;
15-
osx)
16-
stage=$(mktemp -d -t tmp)
17-
;;
13+
linux)
14+
stage=$(mktemp -d)
15+
;;
16+
osx)
17+
stage=$(mktemp -d -t tmp)
18+
;;
1819
esac
1920

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

22-
cross rustc --bin $PKG_NAME --target $TARGET --release -- -C lto
23-
cp target/$TARGET/release/$PKG_NAME $stage/
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
32+
33+
cross rustc --lib --target $TARGET --release -- $linking_args
34+
35+
case $TYPE-$TRAVIS_OS_NAME in
36+
static-*)
37+
cp target/$TARGET/release/lib$PKG_NAME.a $stage/
38+
;;
39+
*-osx)
40+
cp target/$TARGET/release/lib$PKG_NAME.dylib $stage/
41+
;;
42+
*)
43+
cp target/$TARGET/release/lib$PKG_NAME.so $stage/
44+
;;
45+
esac
2446

2547
cd $stage
2648
tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz *

templates/lib/travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ matrix:
1212
include:
1313
- env: TARGET=armv7-unknown-linux-gnueabihf
1414
rust: nightly
15-
- env: TARGET=x86_64-unknown-linux-musl
15+
- env: TARGET=x86_64-unknown-linux-musl TYPE=static
1616
rust: nightly
1717
- env: TARGET=x86_64-apple-darwin
1818
rust: nightly

0 commit comments

Comments
 (0)