landley / toybox

toybox
http://landley.net/toybox
BSD Zero Clause License
2.4k stars 335 forks source link

[Feature request] Could a static-option be added to the menu interface? #491

Open rubyFeedback opened 5 months ago

rubyFeedback commented 5 months ago

Toybox offers some curses based menu. This is similar to busybox.

However had, in busybox there is an option called "compile as static binary", or something like that. Could toybox also add such a Setting or Configure option?

I understand we can probably work around this using LDFLAGS or what not, but I'd prefer a configuration option via the menu interface.

Static binaries can be nice because if things break on the host system, a static binary may still work and thus can be used to fix things.

oliverkwebb commented 5 months ago

Toybox offers some curses based menu. This is similar to busybox.

An old version of 2.6 menuconfig taken from busybox (who took it from the linux kernel). That is (from my knowledge, in the early stages of) being replaced because of licensing (0BSD is not compatible with GPLv2)

However had, in busybox there is an option called "compile as static binary", or something like that. Could toybox also add such a Setting or Configure option?

From my knowledge of the infrastructure We have no such method of doing so. Compiler flags are generally a compile time thing, not a configuration time thing.

I understand we can probably work around this using LDFLAGS or what not, but I'd prefer a configuration option via the menu interface.

My suggestion, if you really want it; is to add this block to the Config.in:

config STATIC
    bool "Staticly Build toybox"
    default n

Then have a script grep -q for "#define CFG_STATIC 1" (in generated/config.h) and add LDFLAGS=--static (and maybe CC=musl-gcc since glibc doesn't staticly link well) on build time.

Static binaries can be nice because if things break on the host system, a static binary may still work and thus can be used to fix things.

You can build a staticly linked binary of toybox with make LDFLAGS=--static (glibc will whine tho, I'd recommend musl for this)

landley commented 5 months ago

I build with "LDFLAGS=--static" all the time. (So does mkroot/mkroot.sh when it builds toybox for the target.) I don't generally add config options for compiler flags you can easily add on the command line.

Also, static linking on glibc is terrible and intentionally broken. I ranted about it a bit in the FAQ at https://landley.net/toybox/faq.html#targets and it comes up here ala https://github.com/landley/toybox/issues/418 where people blame me for glibc and I try to explain glibc to them. (The android NDK has a few screws missing from its static support too, but nowhere near to glibc's levels. Works fine on musl.)

terefang commented 5 months ago

could you make an exception for all those musl users (on Alpine, etc )out there or static musl on glibc systems ?

https://github.com/landley/toybox/issues/496

landley commented 5 months ago

What do you mean by "exception"?

Also, you closed the other issue before I was done with it, see commit mentioned there.

terefang commented 5 months ago

maybe is was too brash about it.