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

Tier 3 OpenBSD Support for x86_64 #2016

Open
andrewrk opened this issue Feb 27, 2019 · 21 comments
Open

Tier 3 OpenBSD Support for x86_64 #2016

andrewrk opened this issue Feb 27, 2019 · 21 comments
Labels
arch-x86_64 64-bit x86 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-openbsd standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

Here's the issue to track OpenBSD support. The current goal is Tier 3, since Zig can't even build on OpenBSD yet. Once Zig reaches Tier 3 this issue will get renamed to Tier 2, and so on. @Aversiste has started the effort in #1921.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library. stage1 The process of building from source via WebAssembly and the C backend. arch-x86_64 64-bit x86 os-openbsd labels Feb 27, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Feb 27, 2019
@andrewrk
Copy link
Member Author

Here is some partially finished code that one can use for inspiration: #1921

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Apr 30, 2019
@andrewrk
Copy link
Member Author

SourceHut has OpenBSD images now: https://man.sr.ht/builds.sr.ht/compatibility.md#openbsd

@voutilad
Copy link

voutilad commented Jun 25, 2019

FWIW, OpenBSD recently imported LLVM 8.0.0 into base: https://marc.info/?l=openbsd-cvs&m=156132754603489&w=2

It's available now in the latest -current snapshots for anyone interested in this issue.

Edit: SourceHut seems to have the latest release, but doesn't support -current snapshots, so anyone working on OpenBSD compatibility can't readily solve the CI needs until the next OpenBSD release later this year.

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Oct 17, 2019
@justjosias
Copy link
Contributor

I am willing to help out with OpenBSD support. I have looked through the previous PRs (particularly #5324), and would like to tackle it, getting Zig to even compile on OpenBSD and getting those changes merged into master.

@andrewrk
Copy link
Member Author

Happy to hear that @justjosias . My suggestion is to make smaller PRs that can be merged independently, making incremental progress. I think you will meet with swift success if you do this.

@kivikakk
Copy link
Contributor

@justjosias 👋 also keen to see Zig on OpenBSD; happy to work with you on testing/iterating on your changes.

@gaultier
Copy link

gaultier commented Sep 3, 2020

OpenBSD-current just added llvm 10 to their (binary) packages. Maybe this could rejuvenile this effort?
You can do: pkg_add llvm and you'll get llvm 10 libraries.
However, when trying to build zig, it will then complain that llvm is missing the target AArch64 and that zig requires all default targets.

@justjosias
Copy link
Contributor

justjosias commented Sep 4, 2020

@gaultier You have to compile LLVM from source, which isn't so hard (the boostrap works very well, just need to add some linker and header include paths). At that point you have to patch and modify Zig to get it to build, which currently is the goal of this issue.

@gaultier
Copy link

gaultier commented Sep 18, 2020

@justjosias Right, got it, I did just this and I realized OpenBSD is not in the list of supported OSes in the zig source code. Hopefully someone can continue the porting effort that was started in the linked PR 👍

@semarie
Copy link
Contributor

semarie commented Oct 9, 2020

FYI I started a port of zig for OpenBSD : https://github.com/semarie/zig/tree/openbsd
it is based on LLVM version from ports (full llvm-10), and I am able to build a stage2 zig compiler.

some work is still need:

  • linkage (to build zig compiler I had to explicitly pass c++ libraries)
  • proper selfExePath implementation (OpenBSD doesn't provide such facility at all)
  • linkage errors will running test-behavior
  • etc...

@jedisct1
Copy link
Contributor

jedisct1 commented Oct 9, 2020

Awesome news, thank you @semarie!

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@vazub
Copy link

vazub commented Nov 17, 2022

@semarie are you still working on this? looks like your repo is not there anymore

@semarie
Copy link
Contributor

semarie commented Nov 17, 2022

I build zig semi-regulary on OpenBSD using upstream repository without issues (and I sent PR to fix them when I saw a problem).

and OpenBSD has a port for zig in official OpenBSD port-tree (but it is disabled due to too big memory requirement to build it from scratch).

@vazub
Copy link

vazub commented Nov 17, 2022

@semarie Does this mean this ticket can be closed as Done now? Or is there anything pending from the list you mentioned above? I assume selfExePath resolution might still be the issue?

@semarie
Copy link
Contributor

semarie commented Nov 17, 2022

zig std has an alternative code for selfExePath as best-effort.

my last build was one month ago (with repository at 99c3578). for me, it should be marked as Done, even if currently is doesn't build (see #13565 where OpenBSD is also impacted).

@Vexu Vexu removed the stage1 The process of building from source via WebAssembly and the C backend. label Dec 7, 2022
@vazub
Copy link

vazub commented Jan 3, 2023

Looks like the fixes for the blockers have been merged @semarie

@andrewrk
Copy link
Member Author

andrewrk commented Jan 3, 2023

but it is disabled due to too big memory requirement to build it from scratch

In case you missed it, #6485 is resolved now :-)

@kuon
Copy link
Contributor

kuon commented Feb 8, 2023

I sadly do not have a lot of time to contribute code to this issue, but I'd like to let you know that we use OpenBSD quite a bit for servers and routers, and I'll be happy to help testing.

@LowByteFox
Copy link

LowByteFox commented Aug 21, 2023

I am currently running OpenBSD 7.3-Current and I've tried to compile zig 0.11.0. It's not possible to compile getFdPath. Before I tried to compile zig @oven-sh uses but the stage 3 compiler was segfault-ing.

What got me confusing is that on release notes of zig 0.11.0 under Tier 2, OpenBSD has ✅ but should have 📖 because it doesn't compile. I don't know if it got there by accident or you just cross-compiled it without being on OpenBSD, I don't know how you got it.

If someone wants to compile it themselves, I provide llvm16 pre-built binary for amd64 OpenBSD 7.3-current in releases. I compiled it as zig's wiki tells me. + Don't forget to install it into /usr/local/llvm16

Before compiling zig, edit /etc/login.conf and for staff increase datasize-cur to 6000M just so clang doesn't fail with Out of Memory error. Don't forget to log out and log in, the confirm it with uname -a under data

My configure command was

cmake .. -DZIG_STATIC_LLVM=ON -DZIG_STATIC_ZSTD=ON -DZIG_STATIC_ZLIB=ON -DZIG_USE_LLVM_CONFIG=OFF  -DCMAKE_PREFIX_PATH="/usr/local/llvm16;/usr/local"

Then run make edit_cache and enter advanced mode
under CMAKE_EXE_LINKER_FLAGS add -lexecinfo so when zig 2 will build it doesn't fail with missing backtrace

Now you are good to go, the compilation should fail with
image

If anything, I can learn zig and try to fix std myself

Update:
I made very nasty fix
image
Just so i would test how far it would get and it got to
image

@LowByteFox
Copy link

LowByteFox commented Sep 4, 2023

I am back with more info, okay so I tried to cross compile simple hello world application. But it crashes with SIGSEGV

I ssh mounted a computer running OpenBSD (You don't need to have a computer with OpenBSD. Just make QEMU VM, forward ssh port and mount / using sshfs) and modified output of zig libc just so it matches ssh root mount. Then I simply executed
zig build --libc openbsdlibc.txt -Dtarget=x86_64-openbsd -Doptimize=ReleaseSmall

Reason why ReleaseSmall is because it doesn't require the missing getcontext symbol and compiles. Then I just copied the output executable to the computer and executed it. It just segfaulted.

It could either be because of the "nasty fix" or who knows what.
I'll share my ktrace output here

I could theoretically fork their libc, add own implementation for storing FDs and call it from zig and try that out, if it would work without breaking anything on the system itself, I would make the patch available on custom repo so users could patch libc and recompile it themselves. I wouldn't make PR back to OpenBSD because this would be home made fix.

But then again, issue can be with something else

@bilaliscarioth
Copy link
Contributor

bilaliscarioth commented Dec 29, 2023

Found a little issue when std:Build.LibExeObjStep.linkSystemLibrary is used on OpenBSD with zig (master branch)

idk for which reason that doesn't work well because every function used on Zig come from of a C Static/Dynamic library ( example SDL2/GL/X11...) are `undefined symbols

Actually works if i used std:Build.LibExeObjStep.addObjectFile where i put the paths of the object (dynamic or not)

PR : #18475

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 64-bit x86 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-openbsd standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests