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

Adjust Nix infrastructure to support passing custom target CPU and -march flags #540

Open
knightpp opened this issue Jul 28, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@knightpp
Copy link

With 649e9da and release of v0.4.5 I can no longer run aarch64 executables and OCI images from the release page.

Even Raspberry 4 does not support Arm8.2, so this change limits self-hosting capabilities. Consider targeting something like a53 or producing artifacts for multiple optimization levels.

@girlbossceo girlbossceo added the bug Something isn't working label Jul 28, 2024
@girlbossceo
Copy link
Owner

Hi! I did try to do a lot of research on what I should pick but I was having trouble finding a consistent answer on what most Raspberry Pi's supported. Sorry this broke 0.4.5 for you! I'm happy to lower it to a more reasonable level if you found one already.

I see you made this knightpp@e579279 and I would accept a PR for it, but it has a ton of other formatting changes which I'd like to have split up into separate commits.

@knightpp
Copy link
Author

I see. I'll try to do my own research, but I'm unsure what was the reason to change the target optimization level in the first place? target-cpu=generic is a good(?) default.

The formatting changed because I use alejandra to format Nix files. I didn't intend to make a PR out of that.

@girlbossceo
Copy link
Owner

It's primarily for optimisation. conduwuit uses RocksDB, which is C, so having highly optimised bytecode makes a significant difference. We also use musl, which is slow, so any forms of optimisation also make a big difference hence things like jemalloc and io_uring are statically included in the static binaries.

@knightpp
Copy link
Author

knightpp commented Aug 4, 2024

I don't know if there's a middle ground. To get the best optimizations, everyone should customize and compile for their CPU, but on my(mid 8C) machine, full cross-compilation for ARM took ~2 hours, so it's not an easy task.

Another option is to add multiple CPU targets to the CI, though it won't reuse previous caches.

I'll continue building it for myself, but leave this issue open. However, there's room for improvement. It would be great to add documentation on how to cross-compile and improve Nix to be able to pass target CPU.

FIY: How to list CPU features

rustc --target aarch64-unknown-linux-musl -C target-cpu=cortex-a55 --print cfg

@girlbossceo
Copy link
Owner

improve Nix to be able to pass target CPU.

I don't really know Nix to be able to add something like this, this will be something the community has to contribute unless I do manage to figure out (not this week).

As for cross-compilation documentation using Nix, I can work on that.

I did decide to just drop it down to ARMv8-A which I will merge/add soon (busy this week) and depending on what the community needs, I can figure out multiple target arch builds in CI. Though I don't think we'll run into this issue that much. I haven't produced (or even tested) ARM 32-bit builds and no one's really mentioned a need for them.

@knightpp
Copy link
Author

knightpp commented Aug 4, 2024

improve Nix to be able to pass target CPU.

I meant to pass optimization level as a string to Nix functions, because right now it is hardcoded into nix/pkgs/main/cross-compilation-env.nix and nix/pkgs/main/default.nix. That might be handy when someone decides to compile for themselves for some very specific CPU.

@girlbossceo girlbossceo changed the title Consider lowering target aarch64 architecture Adjust Nix infrastructure to support passing custom target CPU and -march flags Aug 8, 2024
@girlbossceo girlbossceo added enhancement New feature or request and removed bug Something isn't working labels Aug 8, 2024
@girlbossceo
Copy link
Owner

Going to change this to a feature request for the requested Nix infrastructure as I've dropped the target CPU to ARMv8-A, so next release and currently main should be "fixed".

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

No branches or pull requests

2 participants