WIP: Generate Rust sysexits bindings without bindgen #129

Draft
trinity wants to merge 7 commits from sysxs into main
Owner

rust-bindgen isn't packaged for OpenBSD/arm64, my operating system. I can't compile it, as even with 2GB RAM I always run out of memory.

We use bindgen to generate Rust bindings for a bunch of cpp(1) #defines. Rather than use a program that can't compile on a system with enough memory to hold one thousand copies of DOOM, this patch set simply uses awk(1p), a standard POSIX utility, to rewrite the #define key val lines as pub const key: i32 = val; and then compile those to an rlib. In practice this works quite well and should on any POSIX system, rather than only those systems that have been blessed with binary packages available for them. It also fixes the build for swab(1), which I used to test that this was working.

While bindgen is a part of the Rust toolchain, this patch set is an elegant and portable replacement of the functionality that will save users from having to install yet another development package. On OpenBSD the only dependency of harakit that isn't included in base is rustc, which is obviously irreplaceable (except by another rustc).

[rust-bindgen](https://github.com/rust-lang/rust-bindgen) isn't packaged for OpenBSD/arm64, my operating system. I can't compile it, as even with 2GB RAM I always run out of memory. We use bindgen to generate Rust bindings for a bunch of cpp(1) `#define`s. Rather than use a program that can't compile on a system with enough memory to hold one thousand copies of DOOM, this patch set simply uses awk(1p), a standard POSIX utility, to rewrite the `#define key val` lines as `pub const key: i32 = val;` and then compile those to an rlib. In practice this works quite well and should on any POSIX system, rather than only those systems that have been blessed with binary packages available for them. It also fixes the build for swab(1), which I used to test that this was working. While bindgen is a part of the Rust toolchain, this patch set is an elegant and portable replacement of the functionality that will save users from having to install yet another development package. On OpenBSD the only dependency of harakit that isn't included in base is rustc, which is obviously irreplaceable (except by another rustc).
trinity added the
enhancement
label 2024-06-28 03:38:14 +00:00
trinity added 5 commits 2024-06-28 03:38:15 +00:00
trinity requested review from emma 2024-06-28 03:38:25 +00:00
trinity requested review from silt 2024-06-28 03:38:25 +00:00
trinity added 1 commit 2024-06-28 14:06:37 +00:00
trinity added 1 commit 2024-06-28 14:09:10 +00:00
Owner

This is much less robust and requires a user to know the awk programming language well enough to read it. I’m working on a way to cross-compile bindgen(1) to your system.

This is much less robust and requires a user to know the awk programming language well enough to read it. I’m working on a way to cross-compile `bindgen(1)` to your system.
emma closed this pull request 2024-06-28 16:43:26 +00:00
Author
Owner

Why is it less robust? I disagree - this only uses stable Rust features (the code it generates won't be obsoleted) and very elementary Awk features (the empty pattern, print command, and string catenation are often the first things a beginner learns of Awk) that are all also POSIX. If Awk flat-out is not allowed in Bonsai repositories, its functionality can also (awkwardly) be achieved with other POSIX utilities.

Why is it less robust? I disagree - this only uses stable Rust features (the code it generates won't be obsoleted) and very elementary Awk features (the empty pattern, print command, and string catenation are often the first things a beginner learns of Awk) that are all also POSIX. If Awk flat-out is not allowed in Bonsai repositories, its functionality can also (awkwardly) be achieved with other POSIX utilities.
trinity reopened this pull request 2024-06-28 19:51:03 +00:00
Author
Owner

This shouldn't have been closed until discussion reached a conclusion.

This shouldn't have been closed until discussion reached a conclusion.
Owner

@trinity and I have verbally discussed how opposed I am to this change and it has decided to create an alternate solution.

@trinity and I have verbally discussed how opposed I am to this change and it has decided to create an alternate solution.
Owner

@trinity switched to OpenBSD -currentwhich contains a packaged bindgen(1).

@trinity switched to OpenBSD `-current`which contains a packaged `bindgen(1)`.
Owner

I take issue with this. There are rustc flags which can be used to compile things using less jobs and less optimization, sacrificing some build time for less memory usage. Having bindgen(1) as a dependency makes sense for this project.

I take issue with this. There are `rustc` flags which can be used to compile things using less jobs and less optimization, sacrificing some build time for less memory usage. Having `bindgen(1)` as a dependency makes sense for this project.
Author
Owner

I used all the rustc flags I could to pare down system resource usage to no avail. Moving to -current isn't really a big deal to me (sysupgrade -s did it automagically) but is a pain in the ass just to contribute to Harakit especially considering a 12 line patch could replace this multi-megabyte binary I now have on my system.

I used all the rustc flags I could to pare down system resource usage to no avail. Moving to -current isn't really a big deal to me (`sysupgrade -s` did it automagically) but is a pain in the ass just to contribute to Harakit especially considering a 12 line patch could replace this multi-megabyte binary I now have on my system.
trinity changed title from Generate Rust sysexits bindings without bindgen to WIP: Generate Rust sysexits bindings without bindgen 2024-07-01 11:59:22 +00:00
Author
Owner

I'm working on (and nearly done) a sysexits(1) utility that can be used to look up sysexits and print out valid sysexits source files for various languages. It's an even more stable replacement to an already stable solution and provides additional functionality to make system usage easier (e.g. sysexits $? can tell you with what sysexit the previous process exited).

I'm working on (and nearly done) a sysexits(1) utility that can be used to look up sysexits and print out valid sysexits source files for various languages. It's an even more stable replacement to an already stable solution and provides additional functionality to make system usage easier (e.g. `sysexits $?` can tell you with what sysexit the previous process exited).
This pull request has changes conflicting with the target branch.
  • Makefile

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin sysxs:sysxs
git checkout sysxs

Merge

Merge the changes and update on Gitea.
git checkout main
git merge --no-ff sysxs
git checkout main
git merge --ff-only sysxs
git checkout sysxs
git rebase main
git checkout main
git merge --no-ff sysxs
git checkout main
git merge --squash sysxs
git checkout main
git merge --ff-only sysxs
git checkout main
git merge sysxs
git push origin main
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bonsai/harakit#129
No description provided.