-
Notifications
You must be signed in to change notification settings - Fork 2
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
Change to pre-generated bindings, add feature for generating at compile-time #21
Conversation
ead05f7
to
a2e0a8a
Compare
Why? |
|
I will check on my weekend. I want to ask if anyone has 30k bindgen file like this in their projects? |
Thanks!
I decided to research a bit on some random projects I thought of. I tried to find big commited plaintext files, but I also searched for big bindgen files as that's what you asked, altough I don't know if that matters all. As a reference, src/bindings.rs has 1.17 MB. The commands I used are: To get the biggest files:
To get file count:
Repositories:1. libsqlite3-sys / rusqlitehttps://github.com/rusqlite/rusqlite repo file count: 94 commit count: 2259 .git size: 11.4 MB Biggest file: 8.9 MB libsqlite3-sys/sqlite3/sqlite3.c, with bonus of a 8.75 MB libsqlite3-sys/sqlcipher/sqlite3.c Biggest auto-generated by bindgen: 339 kB libsqlite3-sys/sqlite3/bindgen_bundled_version_ext.rs Total size of the 5 files auto-generated by bindgen: 968 kB 2. linux-raw-syshttps://github.com/sunfishcode/linux-raw-sys commit count: 246 .git size: 3.5 MB Biggest file: 645 kB gen/modules/ioctl.h 20 bindgen-generated 100+ kB files src/x86_64/netlink.rs, for many architectures 3. Zuliphttps://github.com/zulip/zulip repo file count: 6593 commit count: 55023 .git size: 453.2 MB Biggest plaintext file: 977 kB zerver/openapi/zulip.yaml 4. Synapsehttps://github.com/matrix-org/synapse repo file count: 1635 commit count: 23391 .git size: 431 MB Biggest plaintext file: 375 kB [contrib/grafana/synapse.json] 14 100+ kB files ConclusionI don't think there's a very big risk, depending on what you consider a big .git. Rusqlite is in a similar situation while also including some VERY big C files and the .git is at 11.4 MB. The bindgen file should be highly compressable and git is able to store different revisions as deltas. My gut feeling is that we're better off than vita-headers, which has about the same amount of code (1.1 MB) but scattered across multiple files, with lots of definitions moving from one file to another (which means more deltas and I don't know how efficient are git packfiles for that).
Mostly yes, if we moved the cfgs to outside of the extern block, removed all
We can do that, but I'm not certain it would be that valuable.
The problems I found were in related to multiple different implementations of the same function, each using their own cfg. We don't have anything similar AFAIR, so it may not apply to us, unless there are other problems. I think it's reasonable to give it a try. |
That was definitely thorough research. Wow. Then it's ok. |
Hm, i think we can just split up the file into multiple parts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of this PR, but couple of issues should be resolved.
Sorry for a big delay. I kinda forgot about reviewing cause i didn't leave the note for myself. 😅 I promise I'll try help anytime I have from now on. |
No problem! Most changes are good to be reviewed again (with pending discussions about the first 2) |
I gave it a try on another branch: 41c6f6b The file size reduced from 1,170,678 to 880,974 bytes and the code didn't get more complex IMO. |
To reduce dependencies for vitasdk-sys package
"build-util" is identical to profile used by build.rs
Removes need for bindgen during docs.rs build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Added some functionality, feel free to modify if you don't like something.
All changes LGTM. One question though, did you take a look at commit 41c6f6b on branch |
Probably should, since we already preprocess them via syn. I liked new These things look like they have a simpler approach. Maybe we should just render items as text, sort and then reparse them back? Well, current sort visitor is fine tho. |
Also code doesn't use empty extern blocks with |
I'm not sure what you mean by this, so maybe? I am mutating
Kinda agree with you here, the reason I made it that way is because Link doesn't really need to visit recursively while it seems like VisitMut is for recursive traversal. If you still think it would be better that way, go ahead. I made a change to sort foreign mods by features instead of the first item, to make it more consistent. The code is complicated and can surely be improved (e.g. by using When we merge this, we should probably squash and merge to avoid having all of the different bindings.rs versions on PS: The CI issue seems related to rust-lang/rust#119026 |
Eh, it works so whatever. Maybe a task for someone that would find this code irritating enough. |
Hmmmm unfortunately I don't have a more general solution, but we can pub type __gnuc_va_list = u32; |
We could put a check for llvm version only if it is not build.rs, filter out these items (transforming the code) so it would be just like you have said, or add a CI check that would run |
Oh, I'm already adding a check that re-generates the bindings and checks if there's no diff: vitasdk-sys/.github/workflows/build.yml Lines 246 to 312 in d458151
You can see it failing for this commit: cee2090 I like the
Yeah, I'll add a note there |
Well, it seems someone broke std or libc for |
Yep, see rust-lang/libc#3538 |
Changed to use pre-generated bindings by default, with the option of generating bindings at compile-time using the headers at
$VITASDK
by enabling thebindgen
feature.I tried to keep approximately the same style in build-util. I did not add error handling. To re-generate the bindings you can just run:
$ cargo run -p vitasdk-sys-build-util -- bindgen
Also, one curious side effect, the cargo package (compressed) is now less than half the size!
Ordering
Part of the bindings were being generated in an essentially random order, due "random" HashMap iteration order, affecting mostly things related to the stubs/features. Changing those to BTreeMaps made it predictable (possibly deterministic).
One problem that remained is that when updating the vita-headers submodule, many of the bindings would move due to bindings being generated in inclusion order. For that I created a function to sort the bindings based on the identifier, and related header are still usually close due to naming conventions. Tried to keep the sorting code simple, so I depended on some things already being generated in the correct order and the stability of
sort_by_cached_index
. I'm fine with changing that.To Do (Done!)
bindgen
feature is renamedThese are not necessarily blocking release:
cargo run -p vitasdk-sys-build-util -- bindgen