Skip to content

Conversation

willnode
Copy link

@willnode willnode commented Sep 4, 2025

I'm in process to port Zig into a new OS so I use bootstrap.c to make porting process easier. At the last step, gcc fails to link because it links into wrong libc but there's no way to add custom compiler envars into bootstrap.c.

This PR aims to bring support cross compiling in bootstrap.c using these new flags:

  • ZIG_HOST_TARGET_CC
  • ZIG_HOST_TARGET_CFLAGS
  • ZIG_HOST_TARGET_LDFLAGS

I've confirmed it linking to the correct libc after I set these flags.

@alexrp
Copy link
Member

alexrp commented Sep 4, 2025

I don't know if this is a use case we want to support. I think the goal of bootstrap.c is to be as simple as possible to get a working zig binary on the current platform. After that, what stops you from using that zig binary to do zig build -Dtarget=...?

@willnode
Copy link
Author

willnode commented Sep 4, 2025

Redox OS haven't port Clang/LLD so I can't use zig build, and I'm lack of reading needed to cross compile a Zig compiler, and Redox OS mainly build software via cross compiling.

@alexrp
Copy link
Member

alexrp commented Sep 4, 2025

Redox OS haven't port Clang/LLD

That's kind of surprising. It really should not be a lot of work... could probably do it in an evening if you follow an example like Managarm:

After that, you'll need to add an std.Target.Os.Tag.redox tag in Zig and appropriate handling of that in a few places. This is also straightforward; can just grep for other OS tags to see what needs to be done.

However, the other problem you'll run into is likely #23905. You might be able to supply a custom libc.txt to work around this. The ideal solution would of course be for Redox OS to stabilize their libc so we can provide the stub library when cross-compiling, but I don't know when that's going to happen.

@willnode
Copy link
Author

willnode commented Sep 4, 2025

Thank you for these pointers, I'll try to port them and make zig build works. It's nice to see Redox OS have been considered in the past.

I have done tagging redox in my zig branch, at the moment it's almost compiling, just missing some C function in the Redox part. I happen to also port other programs like Go, and they have C definition generator so I would have noticed if ABI break someday.

I'll close this right now, thanks!

@willnode willnode closed this Sep 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants