-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
New approach: link section #26
Conversation
* improve error message when asset does not exist * change fs error message for images too * manifest path hint when path is not a file * typos in error message * store IO error
This opens a possibility of making a truly single-file server binary that not only doesn't depend on shared libraries (but I think this is not currently possible for glibc-based OSes), but also contains all of the assets within. Despite a very nice feature of not having any problems with relative asset paths, this will heavily increase the binary size for medium/big projects. But for blog post-like websites this is probably still an interesting idea.
Is this what will be in the last version of this PR? Am I the only one who thinks that sprinkling |
This PR contains all my work to implement the linker-based approach for next major version of manganis.
A lot of ideas are taken from linkme
General idea
In rust, you can add an attribute to a static to make rust store it in a specific section of the object file.
Then if you look at the object files generated by rustc, you will see that the "foo_section" indeed contains some data.
The idea is then to generate these special static variables containing the description of the assets, ensure rust will store them for each dependency, and ensure the linker will merge all these sections in the final executable.
Then, the job of
manganis-cli-support
will be to read from the executable, retrieve the asset descriptions and use that to add the assetsMacro
The
MANIFEST = mg!(file("Cargo.toml"))
macro invocation will generate something likeThe macro still checks the existence of the path, but it doesn't do anything more complicated. In particular it don't touch the filesystem except for logs
Cli support
The new methods now are:
The
AssetManifest
type also changed, it is now a simple vec ofAssetType
.The load function is much simpler than before:
Init
To force the linker to include all the sections in the final executable, the most robust and straight-forward way seeems to be:
It makes the linker see that it needs "__start_manganis", so it will keep the manganis section of the binary and of every nested dependency
This function is defined at the end of
src/lib.rs
in the main manganis crateLinker
The new file
common/src/linker.rs
defines the section names and link names for different platforms, likelinkme
does.Caveats
There are some things to improve:
manganis::init