-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Better Non-Rust Dependency Tracking in Cargo #1972
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
Comments
What would go in Cargo.lock for a non-Rust dependency? |
TBH, I am not 100% sure since we cannot guarantee versioning for non-Rust build systems. One could imagine a few alternatives:
My leaning is towards the commit hash option for source controlled repos and the "simply a boolean" option for anything else. I am not sure if cargo could/should try to do a consistent versioning scheme for all non-rust dependencies, though. It seems like it would be a good idea, especially for source-controlled dependencies where there is a notion of versions. But it could just be confusing if the dependencies is something you curl and untar or something like that. There are a couple of related questions that this brings up too:
|
You can package cargo with non rust code, look at curl-sys for an example. It could though be made more ergonomic, but without sacrificing stuff like pkg-config checks. |
@est31 This does raise an interesting question: is it enough to just provide a really nice Also, a related note from some experimenting I did today... It would be nice if cargo left behind a symlink to most recent build it has done in some fixed location which does not depend on whether the build was a release or debug build. That way, larger build systems can invoke cargo and just look in one place for the artifact, rather than having to remember if they should look in target/debug or target/release... |
So, just an idea: support building non-rust code with cargo. Add C++ package and build management. They really would like, and need, a cargo-alike. Why not use actual cargo? 😺 (this is mostly because I hate, when writing C++, the lack of a good build system) |
@ubsan The idea sounds great in principle, but I am hesitant... This seems like it would open a new kettle of worms. Why just C++? What about C? Or Python? Or Java? I think if Cargo also tries to be a build manager for every language, it will stretch too thin (unless somebody comes up with a really clever idea). There are already lots of good, well-supported, well-known build managers out there. In my mind, the real value of Cargo is semantic versioning (which every large multi-component has problems with) and crates.io. That's what other languages are (sorely) missing IMO. What would be cool IMO is if Cargo/crates.io could add semantic versioning to other languages (or really, arbitrary projects), which does not seem like much of a stretch (or even a long distance from what we have), but then shells out build management to some other build system, like make... |
You can run build sytem of foreign languges from |
@Dushistov I would still argue that running other build systems through 👍 I do agree with the caching problem. My recent experiments have been of the form "make starts cargo", so I had forgotten about that. |
@Dushistov There are a bunch of directives you can print from the build script to handle error output, track input files, trigger various effects for the actual final compilation etc. Not sure if/where they're documented. |
They are documented here, in particular you can use But anyway, I don't really see how Cargo can expand in scope to manage other languages -- it interacts with Rust's design quite a bit to ensure reproducible builds etc. Maybe a lack of imagination on my part. We can and should develop better build script utilities along the lines of the |
Nope, I have trouble imagining it, too, but we can dream 😛 Also, thanks @eddyb and @durka for the info; I was not aware of those... It strikes me that even though the crate.io docs are pretty thorough, it still seems like there are features of Cargo I am completely unaware of! Maybe another book is in order? The Cargo book + Cargonomicon 😝 |
Also, you're not supposed to write your own build scripts from absolute scratch most of the time, and I believe the |
@mark-i-m mostly a joke, unless someone actually wants to take it up. I just... I really don't want to have to use any build systems but cargo. |
Another passing idea: we could require that the dependency is in a git repo or other VCS as a first pass (we could extend it later). A [dependencies.my_cpp]
git = "http://github.com/example/my_cpp.git"
version="40a964bf658d3fff9a956634d4dfeaf54547b089"
non-rust-build = "make build" |
I think #2136 solves this |
Going to close in favor of #2136 to reduce clutter |
Hey all,
I have been working on a few projects that involve C++ and assembly code with Rust, and one of the annoying pain points is build systems. Here are some thoughts I had. Any feedback or alternate solutions are welcome. Thanks 😄
I propose adding an optional field in the
[dependencies]
section(s) ofCargo.toml
to allow Cargo to be minimally aware of non-Rust dependencies and remove some boilerplate.Suppose the
my_asm
dependency contains some assembly that needs to be built before the rust project. Thenon-rust-build
field in the snippet above tells Cargo that it should just invokemake build
and ensure that it completes with a 0 error code before continuing with the rest of the build. To the very best of my knowledge and from spending some time skimming through the docs on dependencies on crates.io, I don't think such a feature exists yet (please correct me if I am wrong).Motivation
So far, Cargo is great at tracking rust dependencies, but not so great for projects with mixes of rust and not-rust. For example, suppose you have a Rust project with a dependency on some assembly code. You need to first compile the assembly into some sort of object before it can be linked in with your Rust program (aside: #1489 would make the linking portion significantly easier). AFAIK, you can take either of two routes: (1) write a big makefile (or some other build tool) to invoke Cargo, gcc, and then the linker, or (2) use a Cargo build script to invoke the makefile. Such build systems can get messy and hard to debug and require a lot of boilerplate. In some cases, it is just more ergonomic to write a makefile that invokes rustc directly, and I have done this in one of my projects.
To be clear, I not proposing Cargo as a replacement for make. I simply think that Cargo could be made more aware of the other dependencies and build systems in a project in some minimal way.
Specifically, I think there are two cases from the point of view of Cargo: (1) the Rust crate is dependent on some non-Rust object which needs to be obtained somehow, and (2) the Rust crate is a dependency of some non-Rust object which needs to obtain the Rust object before it can be compiled/linked. I would argue that in case (2), some other build system should be responsible for tracking dependencies and making sure that Cargo is invoked when needed. However, in case (1), I believe Cargo should be responsible for obtaining the needed object, even if that simply involves invoking some programmer-defined command (e.g.
make build
).In my opinion, its ok to have a build system with multiple parts (e.g. cargo + make) as long as the parts are modular, somewhat independent (i.e. they have very limited interactions that are easy to trace and debug), and they don't contain lots of boilerplate.
The text was updated successfully, but these errors were encountered: