Skip to content

Commit

Permalink
Merge pull request #17341 from rzezeski/illumos-updates
Browse files Browse the repository at this point in the history
Illumos/Solaris updates
  • Loading branch information
andrewrk authored Oct 3, 2023
2 parents 47f0860 + dd02658 commit 7733894
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 53 deletions.
30 changes: 22 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.5)
include(CheckSymbolExists)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
Expand Down Expand Up @@ -706,9 +707,25 @@ target_link_libraries(zigcpp LINK_PUBLIC
${CMAKE_THREAD_LIBS_INIT}
)

string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS)
if(ZIG_HOST_TARGET_OS STREQUAL "darwin")
set(ZIG_HOST_TARGET_OS "macos")
elseif(ZIG_HOST_TARGET_OS STREQUAL "sunos")
check_symbol_exists(__illumos__ "" ZIG_HOST_TARGET_HAS_ILLUMOS_MACRO)
if (ZIG_HOST_TARGET_HAS_ILLUMOS_MACRO)
set(ZIG_HOST_TARGET_OS "illumos")
else()
set(ZIG_HOST_TARGET_OS "solaris")
endif()
endif()

string(TOLOWER "${CMAKE_HOST_SYSTEM_PROCESSOR}" ZIG_HOST_TARGET_ARCH)
if(ZIG_HOST_TARGET_ARCH MATCHES "^i[3-9]86$")
set(ZIG_HOST_TARGET_ARCH "x86")
if (ZIG_HOST_TARGET_OS MATCHES "(solaris|illumos)")
set(ZIG_HOST_TARGET_ARCH "x86_64")
else()
set(ZIG_HOST_TARGET_ARCH "x86")
endif()
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "amd64")
set(ZIG_HOST_TARGET_ARCH "x86_64")
elseif(ZIG_HOST_TARGET_ARCH STREQUAL "arm64")
Expand All @@ -720,19 +737,13 @@ elseif(ZIG_HOST_TARGET_ARCH STREQUAL "armv7b")
endif()
string(REGEX REPLACE "^((arm|thumb)(hf?)?)el$" "\\1" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
if(ZIG_HOST_TARGET_ARCH MATCHES "^arm(hf?)?(eb)?$")
include(CheckSymbolExists)
check_symbol_exists(__thumb__ "" ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
if(ZIG_HOST_TARGET_DEFAULTS_TO_THUMB)
string(REGEX REPLACE "^arm" "thumb" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")
endif()
endif()
string(REGEX REPLACE "^ppc((64)?(le)?)$" "powerpc\\1" ZIG_HOST_TARGET_ARCH "${ZIG_HOST_TARGET_ARCH}")

string(TOLOWER "${CMAKE_HOST_SYSTEM_NAME}" ZIG_HOST_TARGET_OS)
if(ZIG_HOST_TARGET_OS STREQUAL "darwin")
set(ZIG_HOST_TARGET_OS "macos")
endif()

if(MSVC)
set(ZIG_HOST_TARGET_ABI "-msvc")
elseif(MINGW)
Expand All @@ -759,6 +770,9 @@ else()
set(ZIG2_LINK_FLAGS "-Wl,-stack_size,0x10000000")
elseif(MINGW)
set(ZIG2_LINK_FLAGS "-Wl,--stack,0x10000000")
# Solaris/illumos ld(1) does not provide a --stack-size option.
elseif(CMAKE_HOST_SOLARIS)
unset(ZIG2_LINK_FLAGS)
else()
set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000")
endif()
Expand Down Expand Up @@ -832,7 +846,7 @@ add_custom_command(
add_executable(zig2 ${ZIG2_C_SOURCE} ${ZIG_COMPILER_RT_C_SOURCE})
set_target_properties(zig2 PROPERTIES
COMPILE_FLAGS ${ZIG2_COMPILE_FLAGS}
LINK_FLAGS ${ZIG2_LINK_FLAGS}
LINK_FLAGS "${ZIG2_LINK_FLAGS}"
)
target_include_directories(zig2 PUBLIC "${CMAKE_SOURCE_DIR}/stage1")
target_link_libraries(zig2 LINK_PUBLIC zigcpp)
Expand Down
4 changes: 4 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ fn addCmakeCfgOptionsToExe(
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
}
},
.solaris, .illumos => {
try addCxxKnownPath(b, cfg, exe, b.fmt("libstdc++.{s}", .{lib_suffix}), null, need_cpp_includes);
try addCxxKnownPath(b, cfg, exe, b.fmt("libgcc_eh.{s}", .{lib_suffix}), null, need_cpp_includes);
},
else => {},
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/std/Thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub const max_name_len = switch (target.os.tag) {
.freebsd => 15,
.openbsd => 23,
.dragonfly => 1023,
.solaris => 31,
.solaris, .illumos => 31,
else => 0,
};

Expand Down Expand Up @@ -123,7 +123,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
else => |e| return os.unexpectedErrno(e),
}
},
.netbsd, .solaris => if (use_pthreads) {
.netbsd, .solaris, .illumos => if (use_pthreads) {
const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);
switch (err) {
.SUCCESS => return,
Expand Down Expand Up @@ -229,7 +229,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
else => |e| return os.unexpectedErrno(e),
}
},
.netbsd, .solaris => if (use_pthreads) {
.netbsd, .solaris, .illumos => if (use_pthreads) {
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
switch (err) {
.SUCCESS => return std.mem.sliceTo(buffer, 0),
Expand Down Expand Up @@ -636,7 +636,7 @@ const PosixThreadImpl = struct {
};
return @as(usize, @intCast(count));
},
.solaris => {
.solaris, .illumos => {
// The "proper" way to get the cpu count would be to query
// /dev/kstat via ioctls, and traverse a linked list for each
// cpu.
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub usingnamespace switch (builtin.os.tag) {
.openbsd => @import("c/openbsd.zig"),
.haiku => @import("c/haiku.zig"),
.hermit => @import("c/hermit.zig"),
.solaris => @import("c/solaris.zig"),
.solaris, .illumos => @import("c/solaris.zig"),
.fuchsia => @import("c/fuchsia.zig"),
.minix => @import("c/minix.zig"),
.emscripten => @import("c/emscripten.zig"),
Expand Down
15 changes: 15 additions & 0 deletions lib/std/c/solaris.zig
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ pub const NI = struct {
pub const MAXSERV = 32;
};

pub const NAME_MAX = 255;
pub const PATH_MAX = 1024;
pub const IOV_MAX = 1024;

Expand Down Expand Up @@ -1069,7 +1070,21 @@ pub const mcontext_t = extern struct {
};

pub const REG = struct {
pub const R15 = 0;
pub const R14 = 1;
pub const R13 = 2;
pub const R12 = 3;
pub const R11 = 4;
pub const R10 = 5;
pub const R9 = 6;
pub const R8 = 7;
pub const RDI = 8;
pub const RSI = 9;
pub const RBP = 10;
pub const RBX = 11;
pub const RDX = 12;
pub const RCX = 13;
pub const RAX = 14;
pub const RIP = 17;
pub const RSP = 20;
};
Expand Down
10 changes: 10 additions & 0 deletions lib/std/crypto/Certificate/Bundle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn rescan(cb: *Bundle, gpa: Allocator) RescanError!void {
.netbsd => return rescanBSD(cb, gpa, "/etc/openssl/certs/ca-certificates.crt"),
.dragonfly => return rescanBSD(cb, gpa, "/usr/local/etc/ssl/cert.pem"),
.windows => return rescanWindows(cb, gpa),
.solaris, .illumos => return rescanSolaris(cb, gpa, "/etc/ssl/cacert.pem"),
else => {},
}
}
Expand Down Expand Up @@ -151,6 +152,15 @@ fn rescanWindows(cb: *Bundle, gpa: Allocator) RescanWindowsError!void {
cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
}

const RescanSolarisError = AddCertsFromFilePathError;

fn rescanSolaris(cb: *Bundle, gpa: Allocator, cert_file_path: []const u8) RescanSolarisError!void {
cb.bytes.clearRetainingCapacity();
cb.map.clearRetainingCapacity();
try addCertsFromFilePathAbsolute(cb, gpa, cert_file_path);
cb.bytes.shrinkAndFree(gpa, cb.bytes.items.len);
}

pub const AddCertsFromDirPathError = fs.File.OpenError || AddCertsFromDirError;

pub fn addCertsFromDirPath(
Expand Down
1 change: 1 addition & 0 deletions lib/std/crypto/tlcsprng.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const os_has_fork = switch (builtin.os.tag) {
.netbsd,
.openbsd,
.solaris,
.illumos,
.tvos,
.watchos,
.haiku,
Expand Down
6 changes: 4 additions & 2 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ pub fn openSelfDebugInfo(allocator: mem.Allocator) OpenSelfDebugInfoError!DebugI
.openbsd,
.macos,
.solaris,
.illumos,
.windows,
=> return try DebugInfo.init(allocator),
else => return error.UnsupportedOperatingSystem,
Expand Down Expand Up @@ -2228,7 +2229,7 @@ pub const ModuleDebugInfo = switch (native_os) {
};
}
},
.linux, .netbsd, .freebsd, .dragonfly, .openbsd, .haiku, .solaris => struct {
.linux, .netbsd, .freebsd, .dragonfly, .openbsd, .haiku, .solaris, .illumos => struct {
base_address: usize,
dwarf: DW.DwarfInfo,
mapped_memory: []align(mem.page_size) const u8,
Expand Down Expand Up @@ -2313,6 +2314,7 @@ pub const have_segfault_handling_support = switch (native_os) {
.macos,
.netbsd,
.solaris,
.illumos,
.windows,
=> true,

Expand Down Expand Up @@ -2386,7 +2388,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
.freebsd, .macos => @intFromPtr(info.addr),
.netbsd => @intFromPtr(info.info.reason.fault.addr),
.openbsd => @intFromPtr(info.data.fault.addr),
.solaris => @intFromPtr(info.reason.fault.addr),
.solaris, .illumos => @intFromPtr(info.reason.fault.addr),
else => unreachable,
};

Expand Down
13 changes: 8 additions & 5 deletions lib/std/dwarf/abi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const mem = std.mem;
pub fn supportsUnwinding(target: std.Target) bool {
return switch (target.cpu.arch) {
.x86 => switch (target.os.tag) {
.linux, .netbsd, .solaris => true,
.linux, .netbsd, .solaris, .illumos => true,
else => false,
},
.x86_64 => switch (target.os.tag) {
.linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris => true,
.linux, .netbsd, .freebsd, .openbsd, .macos, .ios, .solaris, .illumos => true,
else => false,
},
.arm => switch (target.os.tag) {
Expand Down Expand Up @@ -194,7 +194,7 @@ pub fn regBytes(
const ucontext_ptr = thread_context_ptr;
return switch (builtin.cpu.arch) {
.x86 => switch (builtin.os.tag) {
.linux, .netbsd, .solaris => switch (reg_number) {
.linux, .netbsd, .solaris, .illumos => switch (reg_number) {
0 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.EAX]),
1 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.ECX]),
2 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.EDX]),
Expand Down Expand Up @@ -229,7 +229,7 @@ pub fn regBytes(
else => error.UnimplementedOs,
},
.x86_64 => switch (builtin.os.tag) {
.linux, .solaris => switch (reg_number) {
.linux, .solaris, .illumos => switch (reg_number) {
0 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.RAX]),
1 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.RDX]),
2 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.RCX]),
Expand All @@ -247,7 +247,10 @@ pub fn regBytes(
14 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.R14]),
15 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.R15]),
16 => mem.asBytes(&ucontext_ptr.mcontext.gregs[os.REG.RIP]),
17...32 => |i| mem.asBytes(&ucontext_ptr.mcontext.fpregs.xmm[i - 17]),
17...32 => |i| if (builtin.os.tag.isSolarish())
mem.asBytes(&ucontext_ptr.mcontext.fpregs.chip_state.xmm[i - 17])
else
mem.asBytes(&ucontext_ptr.mcontext.fpregs.xmm[i - 17]),
else => error.InvalidRegister,
},
.freebsd => switch (reg_number) {
Expand Down
4 changes: 2 additions & 2 deletions lib/std/dynamic_library.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const system = std.os.system;
pub const DynLib = switch (builtin.os.tag) {
.linux => if (builtin.link_libc) DlDynlib else ElfDynLib,
.windows => WindowsDynLib,
.macos, .tvos, .watchos, .ios, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris => DlDynlib,
.macos, .tvos, .watchos, .ios, .freebsd, .netbsd, .openbsd, .dragonfly, .solaris, .illumos => DlDynlib,
else => void,
};

Expand Down Expand Up @@ -388,7 +388,7 @@ pub const DlDynlib = struct {

test "dynamic_library" {
const libname = switch (builtin.os.tag) {
.linux, .freebsd, .openbsd => "invalid_so.so",
.linux, .freebsd, .openbsd, .solaris, .illumos => "invalid_so.so",
.windows => "invalid_dll.dll",
.macos, .tvos, .watchos, .ios => "invalid_dylib.dylib",
else => return error.SkipZigTest,
Expand Down
14 changes: 7 additions & 7 deletions lib/std/fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub const Watch = @import("fs/watch.zig").Watch;
/// fit into a UTF-8 encoded array of this length.
/// The byte count includes room for a null sentinel byte.
pub const MAX_PATH_BYTES = switch (builtin.os.tag) {
.linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .plan9 => os.PATH_MAX,
.linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .haiku, .solaris, .illumos, .plan9 => os.PATH_MAX,
// Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
// If it would require 4 UTF-8 bytes, then there would be a surrogate
// pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
Expand All @@ -59,10 +59,9 @@ pub const MAX_PATH_BYTES = switch (builtin.os.tag) {
/// (depending on the platform) this assumption may not hold for every configuration.
/// The byte count does not include a null sentinel byte.
pub const MAX_NAME_BYTES = switch (builtin.os.tag) {
.linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly => os.NAME_MAX,
.linux, .macos, .ios, .freebsd, .openbsd, .netbsd, .dragonfly, .solaris, .illumos => os.NAME_MAX,
// Haiku's NAME_MAX includes the null terminator, so subtract one.
.haiku => os.NAME_MAX - 1,
.solaris => os.system.MAXNAMLEN,
// Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
// If it would require 4 UTF-8 bytes, then there would be a surrogate
// pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
Expand Down Expand Up @@ -326,7 +325,7 @@ pub const IterableDir = struct {
const IteratorError = error{ AccessDenied, SystemResources } || os.UnexpectedError;

pub const Iterator = switch (builtin.os.tag) {
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => struct {
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris, .illumos => struct {
dir: Dir,
seek: i64,
buf: [1024]u8, // TODO align(@alignOf(os.system.dirent)),
Expand All @@ -344,7 +343,7 @@ pub const IterableDir = struct {
switch (builtin.os.tag) {
.macos, .ios => return self.nextDarwin(),
.freebsd, .netbsd, .dragonfly, .openbsd => return self.nextBsd(),
.solaris => return self.nextSolaris(),
.solaris, .illumos => return self.nextSolaris(),
else => @compileError("unimplemented"),
}
}
Expand Down Expand Up @@ -898,6 +897,7 @@ pub const IterableDir = struct {
.dragonfly,
.openbsd,
.solaris,
.illumos,
=> return Iterator{
.dir = self.dir,
.seek = 0,
Expand Down Expand Up @@ -1841,7 +1841,7 @@ pub const Dir = struct {
error.AccessDenied => |e| switch (builtin.os.tag) {
// non-Linux POSIX systems return EPERM when trying to delete a directory, so
// we need to handle that case specifically and translate the error
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => {
.macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris, .illumos => {
// Don't follow symlinks to match unlinkat (which acts on symlinks rather than follows them)
const fstat = os.fstatatZ(self.fd, sub_path_c, os.AT.SYMLINK_NOFOLLOW) catch return e;
const is_dir = fstat.mode & os.S.IFMT == os.S.IFDIR;
Expand Down Expand Up @@ -3007,7 +3007,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
}
switch (builtin.os.tag) {
.linux => return os.readlinkZ("/proc/self/exe", out_buffer),
.solaris => return os.readlinkZ("/proc/self/path/a.out", out_buffer),
.solaris, .illumos => return os.readlinkZ("/proc/self/path/a.out", out_buffer),
.freebsd, .dragonfly => {
var mib = [4]c_int{ os.CTL.KERN, os.KERN.PROC, os.KERN.PROC_PATHNAME, -1 };
var out_len: usize = out_buffer.len;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/fs/file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ pub const File = struct {
os.S.IFSOCK => break :blk .unix_domain_socket,
else => {},
}
if (builtin.os.tag == .solaris) switch (m) {
if (builtin.os.tag.isSolarish()) switch (m) {
os.S.IFDOOR => break :blk .door,
os.S.IFPORT => break :blk .event_port,
else => {},
Expand Down Expand Up @@ -685,7 +685,7 @@ pub const File = struct {
else => {},
}

if (builtin.os.tag == .solaris) switch (m) {
if (builtin.os.tag.isSolarish()) switch (m) {
os.S.IFDOOR => return .door,
os.S.IFPORT => return .event_port,
else => {},
Expand Down
2 changes: 1 addition & 1 deletion lib/std/fs/get_app_data_dir.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
};
return fs.path.join(allocator, &[_][]const u8{ home_dir, "Library", "Application Support", appname });
},
.linux, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris => {
.linux, .freebsd, .netbsd, .dragonfly, .openbsd, .solaris, .illumos => {
if (os.getenv("XDG_DATA_HOME")) |xdg| {
return fs.path.join(allocator, &[_][]const u8{ xdg, appname });
}
Expand Down
Loading

0 comments on commit 7733894

Please sign in to comment.