ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.48k stars 2.52k forks source link

Tier 1 Support for x86_64-solaris #7151

Open nektro opened 3 years ago

nektro commented 3 years ago

https://www.oracle.com/solaris/

The-King-of-Toasters commented 3 years ago

Out of curiosity, I'm currently trying to bring zig up on an Illumos system using OmniOS CE (in a VM). I'm at the point that all that's left to do is write up the required variables/structures in os and bits. I'm wondering if I could get some help from someone experienced in this area?

Here's the process I used to setup the system for testing:

  1. Install OmniOS CE, preferably the "bloody" version (think debian testing). Don't forget to add a admin user and enable dhcp (and sshd if required). Reboot.
  2. Login as an admin, then run pkg update to bring the system up-to-date. Reboot.
  3. As an admin, run pkg install gcc11 git cmake ninja.
  4. OmniOS packages llvm and clang, but not lld. I had trouble building lld on its own, and even building all three from the release tarballs didn't work. Instead I just cloned the monorepo and built all three in one go:
    git clone --depth 1 -b release/12.x https://github.com/llvm/llvm-project.git
    cd llvm-project
    # Apply the same patches for llvm+clang that omnios uses, all in one file
    wget https://www.sgregoratto.me/paste/llvm.patch
    git apply llvm.patch
    cmake -B build -G Ninja \
        -DCMAKE_INSTALL_PREFIX=$HOME/local -DCMAKE_PREFIX_PATH=$HOME/local \
        -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LIBXML2=OFF \
        -DLLVM_ENABLE_PROJECTS="llvm;clang;lld" llvm
    ninja -C build install
  5. Get the zig sources. Before compiling, we have to teach stage1 how long our C ints are with this patch (I verified these numbers myself using a simple test program in C):
diff --git a/src/stage1/target.cpp b/src/stage1/target.cpp
index 7e66d42c4..57cc0253d 100644
--- a/src/stage1/target.cpp
+++ b/src/stage1/target.cpp
@@ -667,6 +667,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
         case OsWASI:
         case OsHaiku:
         case OsEmscripten:
+        case OsSolaris:
             switch (id) {
                 case CIntTypeShort:
                 case CIntTypeUShort:
@@ -723,7 +724,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
         case OsCloudABI:
         case OsKFreeBSD:
         case OsLv2:
-        case OsSolaris:
         case OsZOS:
         case OsMinix:
         case OsRTEMS:
The-King-of-Toasters commented 3 years ago

I understand that there's a specific issue for Illumos (#7152), but since lld doesn't discern between the two I think I'll just stick to "Solaris" as a whole. IIRC there's almost no low-level breaking changes between Illumos and Solaris now.

The-King-of-Toasters commented 3 years ago

Illumos systems are very strange on their own, as they're a mix of Linux, BSD and old-school Unix features, along with some home-grown stuff as well. I'm just gonna assume we want everything, a la #define __EXTENSIONS__.

The-King-of-Toasters commented 3 years ago

I've worked on this a bit more and I've gotten the compiler to link, but that's about all it can do. Libdir detection doesn't work, and you have to manually specify to link against libc to get any sort of meaningful progress. The furthest I've gotten is by running CC=gcc ./zig test -lc --zig-lib-dir ../lib ../test/behavior.zig -I ../test, and even then it does a double panic. I've rebased my work on master, but I don't think I can continue without some help.

The-King-of-Toasters commented 3 years ago

Worked some more on this and updated my fork (under the branch solarish-port). Now most things work, but there's still some bugs. It seems that I'm running into a race issue when using Dir.iterate/Dir.deleteTree, which is causing the fs tests to fail when they clean up (even though they passed fine). There's also the matter of implementing the event loop. Solaris has it's own event system and Illumos augments this with epoll support, but still recommends using the native system.