Comments (6)
I looked into this a little more, and it might be doable:
- It looks like
Cargo.toml
has aninclude
field that allows crates to include extra files as part of the crate to be downloaded fromcrates.io
. - For third-party commands (like
cargo-bundle
), Cargo sets aCARGO
environment variable pointing to thecargo
executable, which allows us to run other cargo subcommands. - The
cargo metadata
subcommand can get us info about the bundled binary's recursive dependencies, includingmanifest_path
fields pointing to theCargo.toml
file for each dependency. - So, when running
cargo-bundle
for a binary, it could usecargo metadata
to find theCargo.toml
files for every dependency, read each one to check for apackage.metadata.bundle.resources
field, follow those paths (relative to eachCargo.toml
path) to find the resource files, and include them in the binary bundle.
Not sure how expensive all that is to do for every cargo-bundle
invocation. It may be that we want this behavior to be off by default, with a [package.metadata.bundle]
field to enable it.
from cargo-bundle.
This isn't currently possible, no. It's not immediately clear to me how it would work -- if this were a feature of cargo-bundle, how would non-cargo-bundled binaries depending on that library know how to find the resources?
Meanwhile, as a workaround, depending on what kinds of resources your library needs, you might consider using the std::include_bin!
or std::include_str!
macros to compile the resource files directly into the library.
from cargo-bundle.
My idea is roughly this:
-
If a library has resources in it's folder tree but the binary built using the library is NOT bundled with cargo-bundler (just cargo let's say) then things would work as now. These files would NOT be included. Either the library and/or the binary would need to be written for the possibility of the files not being there (and either work differently, or fail gracefully). No worse than now, no? If you want bundled resources, you have to use a bundler...
-
if a library has resources in it's folder tree, and they are referenced in [package.metadata] in the library's Cargo.toml and the binary IS packaged with cargo-build, then they would be bundled with the binary and all works OK. (Optional to include a way in Cargo.toml of the binary to strip out resources from dependent libraries?)
-
if the binary also includes resources, then they would be bundled also, into a combined folder tree (with files from any dependant lib) in the resulting binary. Library resources would maybe need to be namespaced by lib name in the folder tree to avoid conflicts.
Get's a bit complicated I know....but it's either this, or we bake all files in as code using include_str!() and the like, to libs and binaries, and then write methods to navigate around and find them....kind of like a FileSystem :-)
Alternative Ideas: I guess I could look at creating a custom Framework (Mac OS) and bundling that? Not sure how it works on other OS....
from cargo-bundle.
Any feedback on the idea @mdsteele ?
Thinking about my project, this is the cleanest way to achieve what I want to do,
but given the complexity, I may need to bail and find another way to achieve it :-(
I guess we'd need to run cargo-bundle on all the dependencies (libs, workspace members) in the build (which is quite a big deal :-( ) and have those assets "bundled" (copied) into the output directory where the final build is done and cargo-bundle would create the final applicaiton bundle when the binary is finally built....
Either way I'll will do work on #42 as that's good for everyone.
from cargo-bundle.
Wow! That's much more encouraging than I expected. I'd kind of given up....
Yes, some kind of "include subproject bundled files" flag would do it!
Options like:
- include all
- exclude all
- include a named list
- exclude a named list
from cargo-bundle.
Now that I've made progress on fixing the workspace awareness, I might be able to attack this in the next week or two (busy all next week).
Where the "included" files are bundled from ("target" directory) should follow the same logic as the non-workspace/workspace case I guess.
I guess that when building a library, the recursive bundling wouldn't need to be done (just let cargo "include" it's own files), as that can be deferred until a binary is built, and then it can do the whole dependency tree.
from cargo-bundle.
Related Issues (20)
- Add release binaries to github releases for easy use with github actions HOT 1
- Adding libvulkan.dylib to ios bundle
- Crashing while install iOS app to Simulator
- How can I use cross and cargo bundle together? HOT 1
- `cargo-bundle` doesn't find correct package in workspace
- `cargo-bundle` should use `bin` target name instead of package name
- Does not respect ~/.cargo/config.toml target-dir setting
- Changing executable and bundle names based on --example argument
- Support Virtual Workspaces (Bundling Multiple Binaries in One Installer)
- short_description is not optionnal HOT 1
- System category from xdg not working
- Icon not showing on Ubuntu 23.10 HOT 1
- Mac M1 termainal can run, but .app crash immediately HOT 3
- About getter pattern HOT 1
- path resolver is broken on nesting rust project HOT 3
- Menu Item name is not shown on macOS
- Linker error `ld: framework not found Security` HOT 1
- Implement Document Handling for macOS
- Support for iOS production bundles HOT 1
- macOS Bundle Icon color messed up HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cargo-bundle.