Skip to content
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

Link native_main statically #50

Open
dshynkev opened this issue Jun 26, 2021 · 4 comments · May be fixed by #81
Open

Link native_main statically #50

dshynkev opened this issue Jun 26, 2021 · 4 comments · May be fixed by #81
Labels

Comments

@dshynkev
Copy link

Currently, native_main is dynamically linked with libc. This is almost never an issue, except for musl users like me. Now, of course, I could just shut up and build my own executables, but, fortunately, static linkage is easy enough to propose universally:

--- nim.cfg.a   2021-06-26 19:41:28.268492678 -0400
+++ nim.cfg.b   2021-06-26 19:41:36.734493221 -0400
@@ -1 +1,2 @@
 d:debug
+l:"-static"

This increases the size of the binary slightly: 484K -> 523K. It should also help with reproducibility (though I doubt there are currently issues with that).

My main reservation with proposing this is that I don't know what this does on systems that aren't Linux, e.g. macOS, where static linking is unsupported. I assume that Nim does not statically link in such cases instead of building a fragile executable.

@bovine3dom
Copy link
Member

The CI we use makes it pretty easy to add flags per OS - so we can just do static linkage for the Linux builds.

See

and
- run: nimble build -d:danger -d:release --opt:speed -Y --verbose
(one day I'd like to work out how to merge these files; the duplication is silly).

A PR would be welcome - otherwise it'll just go on my (very long) todo list :)

@klardotsh
Copy link

Huge +1 to either fixing this with static linking, or providing Musl builds that are detected in the install script. I ran the install script and was trying to figure out why on earth :native still failed - then I remembered, oh right, I'm on Void Musl. nimble build and copying the resulting executable over top of ~/.local/share/tridactyl/native_main, and otherwise making no changes after what all the installer script did, worked fine.

@bovine3dom
Copy link
Member

I think it's just a single line to change in the build scripts. I have never got round to doing it is all

with luck the blocks next release label will make it harder for me to forget about it. If you want it quicker than that, a PR would be welcome :)

@bovine3dom bovine3dom linked a pull request Oct 6, 2024 that will close this issue
@bovine3dom
Copy link
Member

@klardotsh I finally got around to looking at this but it doesn't seem to work, the build is exactly the same size and it's saying that it's dynamically linked https://github.com/tridactyl/native_messenger/actions/runs/11202765381

Do you know what I'm doing wrong? Should I be building it statically using musl for everyone?

$ file native_main
native_main: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=3b7db7b0a9b8c18f8f535bb8317df090c9da8fe2, for GNU/Linux 3.2.0, not stripped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants