Skip to content

Conversation

@hoanga
Copy link

@hoanga hoanga commented May 22, 2021

Hello again,

I have made some more progress in getting Zig to work under Haiku. The following changes should get Zig to compile and build a (simple) Zig program that runs under Haiku. This is compiled with a llvm12 installation (can use pkgman under Haiku for this. relevant packages are llvm12, llvm12_clang, llvm12_libs, llvm12_lld). This was tested on nightly build hrev55081.

Things I have been able to confirm now functional that wasn't previously (previous commands that were working under Haiku should still be):

  • zig cc of a barebones c program appears to compile
  • zig build-exe can generate an executable binary
  • zig run on a zig file works

When running zig build on a sample project I am seeing an error returned along the lines of Unable to dump stack trace: Unable to open debug info: UnsupportedDebugInfo which is to be expected at this time. This most likely also affects make install target as well.

This update also adds an extra returned parameter when running zig libc (crtbegin_dir) to note the extra directory that needs to be returned for what appears to be other bits of the c runtime for Haiku. I am not sure about this change but verified that it is functional at the moment. I would be open to suggestions to better approaches for handling this.

~/src/git/zig/build> uname -a
Haiku shredder 1 hrev55081 May 10 2021 07:04:00 x86_64 x86_64 Haiku

~/src/git/zig/build> ./zig version
0.8.0-dev.2591+4b69bd61e

~/src/git/zig/build> ./zig libc
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=/boot/system/develop/headers

# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=/boot/system/develop/headers

# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=/system/develop/lib

# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=

# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=

# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
crtbegin_dir=/boot/system/develop/tools/bin/../lib/gcc/x86_64-unknown-haiku/8.3.0
~/src/git/zig/build> mkdir hellohaiku
~/src/git/zig/build> cd hellohaiku/
~/src/git/zig/build/hellohaiku> ../zig init-exe
info: Created build.zig
info: Created src/main.zig
info: Next, try `zig build --help` or `zig build run`
~/src/git/zig/build/hellohaiku> ../zig run src/main.zig 
info: All your codebase are belong to us.

}
},
.linux, .netbsd, .freebsd, .dragonfly, .openbsd => struct {
.linux, .netbsd, .freebsd, .dragonfly, .openbsd, .haiku => struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't get any meaningful stack trace until getModuleForAddress is implemented using get_next_image_info.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that has been an item I have been planning to get to (most likely as a separate item).

src/link/Elf.zig Outdated
} else {
break :o "crt1.o";
}
} else if (target.os.tag == .haiku) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on which PR is merged first this conflicts with #8730 or the other way around.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the heads up on this. I will keep an eye out and handle updating the PR if needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both of you. #8730 is merged now. Once this is rebased I think it is ready to be merged. Nice progress on Haiku support!

@hoanga hoanga force-pushed the haiku-support-linker branch from b33a4e8 to f342dee Compare May 24, 2021 02:12
Al Hoang and others added 6 commits May 24, 2021 10:39
* for some reason part of the linkable bits for the crt libraries
  are split in different locations for haiku. this changeset
  accomodates this situation (crtbegin_dir lookup)
@andrewrk andrewrk force-pushed the haiku-support-linker branch from f342dee to 156b968 Compare May 24, 2021 17:45
@andrewrk andrewrk merged commit 0a99898 into ziglang:master May 24, 2021
@andrewrk
Copy link
Member

hi @hoanga - the 0.8.0 release is on June 4 (in 5 days from now). Would you like me to put anything about Haiku into the release notes? If so, please type up some release notes as a comment below, and I will copy+paste it into the Zig 0.8.0 release notes 🙂

@hoanga
Copy link
Author

hoanga commented Jun 7, 2021

hi @andrewrk, my deepest apologies on not getting back in time regarding your question about including Haiku support for the new release (big congrats btw! wish i was available for the party). the notes as added, are just fine as far as i can see.

i really appreciate the added note about Haiku support and hoping to get it even more ready in the future!

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.

3 participants