Skip to content

Commit

Permalink
Improve lib template on Travis
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bltavares committed Oct 10, 2018
1 parent 48fa6fc commit de36827
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions templates/lib/before_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ set -ex

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

case $TRAVIS_OS_NAME in
linux)
Expand All @@ -19,8 +20,29 @@ main() {

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

cross rustc --bin $PKG_NAME --target $TARGET --release -- -C lto
cp target/$TARGET/release/$PKG_NAME $stage/
# TODO: combine with -C lto
case $TYPE in
static)
linking_args="--crate-type staticlib"
;;
*)
linking_args="--crate-type cdylib"
;;
esac

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

case $TYPE-$TRAVIS_OS_NAME in
static-*)
cp target/$TARGET/release/lib$PKG_NAME.a $stage/
;;
*-osx)
cp target/$TARGET/release/lib$PKG_NAME.dylib $stage/
;;
*)
cp target/$TARGET/release/lib$PKG_NAME.so $stage/
;;
esac

cd $stage
tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz *
Expand Down
2 changes: 1 addition & 1 deletion templates/lib/travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ matrix:
include:
- env: TARGET=armv7-unknown-linux-gnueabihf
rust: nightly
- env: TARGET=x86_64-unknown-linux-musl
- env: TARGET=x86_64-unknown-linux-musl TYPE=static
rust: nightly
- env: TARGET=x86_64-apple-darwin
rust: nightly
Expand Down

0 comments on commit de36827

Please sign in to comment.