webui-dev / webui

Use any web browser or WebView as GUI, with your preferred language in the backend and modern web technologies in the frontend, all in a lightweight portable library.
https://webui.me
MIT License
2.96k stars 172 forks source link

Linking with Musl #260

Closed wwderw closed 11 months ago

wwderw commented 11 months ago

Strange thing is that I'm able to get the nim version to compile under musl just fine, but when I try to build it as a C project. Everything compiles and I run ldd, it shows up as statically linked, but it tells me that the file/folder doesn't exist when I try to run it. This is compiling the official 2.3 release. Nightly doesn't seem to want to build regardless if I use musl or gcc (although in the past it has with gcc, so I figured something was going on with nightly)

Any thoughts as to what would be the best way to build for musl?

Thanks for the help.

ttytm commented 11 months ago

Hey @wwderw

to better help you, please also provide info about the platform and compiler version you are using.

Regarding building the nightly version, did you clone the repo and followed the instructions in the readme? If not please try this and share info about the outcome.

wwderw commented 11 months ago

@ttytm

GCC: 13.2.1 Musl: 1.2.4 OS: Arch-linux

Building Nightly with Regular GCC: Yes, I did follow the readme. It had worked previously, just fine. I did complain on it not being .git, which I thought was strange.

2.3 Build: Git clone worked, both doing regular make and doing CC=musl-gcc make (I made sure all intermediate and archive files were removed between build. Regular build went fine. It was only when changing CC to musl-gcc, it would build, but give the previous error msg when I tried to run it, however it would still let me know that it was a static build. I was expecting to get reference issues if I still was using the regular gcc built archive, but no errors like that, built my final binary just fine.

Setup works fine for the nim bindings. Depending on what other libraries I want to use, I may switch between the two (still sometimes easier for me to default to C compared to nim).

ttytm commented 11 months ago

Building Nightly with Regular GCC: Yes, I did follow the readme. It had worked previously, just fine. I did complain on it not being .git, which I thought was strange.

It's likely that you downloaded the source code from the releases and then tried to built it. GitHub won't add the .git repository to Source code releases that are automatically added when a release tag is created. They get stripped of some data.

Screenshot 2023-10-27 at 14 50 17

When a free moment opens up, I'll look into allowing building in the case someone made a Source code download via the releases. Though I'm not classifying it as high priority, since the releases are intended for the pre-built binaries and the common way for developing and building is doing a git clone of the repository.

If you just want a quick copy of a single tag you can do a shallow clone:

git clone --branch nightly --depth 1 https://github.com/webui-dev/webui webui-nightly
cd webui-nightly
make

2.3 Build: Git clone worked, both doing regular make and doing CC=musl-gcc make (I made sure all intermediate and archive files were removed between build. Regular build went fine. It was only when changing CC to musl-gcc, it would build, but give the previous error msg when I tried to run it, however it would still let me know that it was a static build. I was expecting to get reference issues if I still was using the regular gcc built archive, but no errors like that, built my final binary just fine.

Specifying a custom compiler like CC=musl-gcc is currently not supported by WebUIs GNUMakefile. It's likely that just default gcc was used. If you want to use compilers that are not officially supported you either need to do run the full build commands yourself. Or in your case, with musl-gcc, making it available as gcc in your PATH. One way of solving it could be:

# Or whatever path would be used for binaries on your system
ln -s path_to_musl_gcc/musl-gcc /usr/local/bin/gcc
hassandraga commented 11 months ago

CC=musl-gcc is now supported (https://github.com/webui-dev/webui/commit/30a1e49130a412e1ab59eda7ce3a005ad1984318). Thank you @wwderw for pointing this out.

git clone --branch nightly --depth 1 https://github.com/webui-dev/webui webui-nightly

cd webui-nightly
make CC=musl-gcc

cd examples/C/text-editor
make CC=musl-gcc
wwderw commented 11 months ago

@hassandraga @ttytm

Success!! Thank you both for the help. I really do appreciate it.