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

Support building a full workspace or multiple members in the workspace #20

Closed
dmikusa opened this issue Mar 23, 2021 · 4 comments · Fixed by #73
Closed

Support building a full workspace or multiple members in the workspace #20

dmikusa opened this issue Mar 23, 2021 · 4 comments · Fixed by #73

Comments

@dmikusa
Copy link
Contributor

dmikusa commented Mar 23, 2021

Right now the cargo install buildpack uses cargo install with the --path= to install a particular member in a workspace. This works for simple cases, but if you have a workspace with many members, you might want/need to build a subset of the projects or all of them. This isn't currently supported.

Running cargo install --path=foo --path=bar isn't supported, nor is there a --all flag like with cargo build. It only accepts one --path. See rust-lang/cargo#4101.

To resolve this, we need could switch to using cargo build instead of cargo install. This command has controls around building a full workspace or specific packages. The main issue with cargo build is that cargo install nicely places the binaries that are built into the destination layer for us. If we use cargo build there is an --out-dir flag that looks promising, but it's only in nightly Rust at the moment (so it may be a future fix, but doesn't work now). That means the buildpack would be responsible for copying the output to the destination layer manually. The problem is that there is not an easy way to get the targets.

What you'd end up needing to do is run cargo metadata --format-version=1 and parsing the output. This will give you the list of packages in the workspace and then for each package you can find the available targets. The list of installable stuff would be any binary or example target. You could then pull out the binary that's built for each target based on the target name & copy that into the layer. It's not clear what the buildpack would do if a partial build was done, some logic would need to be applied to copy only what was built.

Another option would be to use cargo metadata --format-version=1 to extract the list of packages in the workspace. That list also has the file paths for each package. You could then iterate through each package and do a cargo install --path=<parsed package> to install each. This would let cargo install perform the actual installation for you. The tricky part with this one would be how does the buildpack allow you to pass through flags to cargo install? Is there one set that's applied to all the packages or is there a way to apply per package flags? You'd also have the issue of how to perform a partial build, where you only want a subset of packages. There would need to be a buildpack environment variable that allows the user to indicate this.

@thangchung
Copy link

Hi @dmikusa-pivotal,

I have followed the document on the README file on this repo (https://github.com/paketo-community/cargo-install#bp_cargo_install_args) to pass the --path into cargo-install with the syntax as below

$ pack build vietnamdevsgroup/northwind-rs -e SQLX_OFFLINE=true -e BP_CARGO_INSTALL_ARGS="--path=./apps/actix" 
-b docker.io/paketocommunity/rust

But after the run, it always threw an exception:

image

My repo is at https://github.com/thangchung/northwind-rs

Could you tell me how can I pass args to BP_CARGO_INSTALL_ARGS?

@dmikusa
Copy link
Contributor Author

dmikusa commented Apr 21, 2021

@thangchung - You have it right. I apologize, but I haven't cut a release with that functionality in it yet. I was hoping to get #41 merged as that fixes some other issues too. Let me talk with @ForestEckhardt and see if we can get #41 merged, so I can cut a release. I would love for you to try it out and provide feedback.

As far as this issue, #20. I don't think you'll need that if you are just trying to pass in --path and build a single member of your workspace. That's what it looks like from your Cargo.toml. This feature is to add a way to build and install an entire, multiple binaries, workspace. If you do need this feature, I'm actively working on it, so hopefully I can have something ready in a week or two (sorry, working on this in my spare time).

@dmikusa
Copy link
Contributor Author

dmikusa commented Apr 21, 2021

@thangchung I just cut release 0.0.12 of the Rust CNB, this picks up the latest Cargo Install CNB, version 0.0.7, which has the BP_CARGO_INSTALL_ARGS change as well as a few others I think you'll find helpful. Let me know how it goes. Feel free to open a new issue if there are still problems.

@thangchung
Copy link

Thank you @dmikusa-pivotal. I can set the path when built and it worked 👍

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 a pull request may close this issue.

2 participants