Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve lib template on Travis #19

Merged
merged 2 commits into from
Dec 18, 2018

Conversation

bltavares
Copy link
Contributor

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 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.

Choose one: is this a 🐛 bug fix, a 🙋 feature, or a 🔦 documentation change?
🙋

Checklist

  • tests pass
  • tests and/or benchmarks are included
  • documentation is changed or added

Context

Semver Changes

@@ -6,7 +6,8 @@ set -ex

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get 2 lines indentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated emacs to use 2 spaces as identation, but it keeps wanting to align the variables instead of indenting it.
Should they be indented instead of aligned then?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I don't align any of my code; it's usually harder to have people collaborate on (unless it's enforced by something like gofmt / rustfmt).

*)
cp target/$TARGET/release/lib$PKG_NAME.so $stage/
;;
esac
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get 2 lines indentation here?

Copy link
Owner

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks pretty good to me! -- few small nits, but think we should be good to merge after!

@bltavares
Copy link
Contributor Author

I've used the shfmt CLI to fix indentation. Let me know if there is something else to change.

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>
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>
@bltavares
Copy link
Contributor Author

I've had the time to write a small CLI app to help to produce the correct type of lib, it being either static or dynamic.

You can see the resulting run here and the artifacts here.

Let me know if you would rather have this commits splits, or if there are any concerns with this extra step and dependency

@yoshuawuyts
Copy link
Owner

yoshuawuyts commented Dec 18, 2018

Let me know if you would rather have this commits splits, or if there are any concerns with this extra step and dependency

I'm not seeing any extra dependencies being pulled in; this seems all fine. I say we merge this!

@yoshuawuyts yoshuawuyts merged commit a0b25ce into yoshuawuyts:master Dec 18, 2018
@bltavares bltavares deleted the improve-lib-template branch December 19, 2018 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants