Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
Fixes errno to work on single-threaded targets, adds CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix "xq" Queißner committed Jan 5, 2024
1 parent 3e7253b commit 4c159fa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Continuous Integration

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
single_thread: [true, false]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0

- name: Generate and validate packages
run: |
zig build -Dsingle-threaded=${{ matrix.single_thread }}
3 changes: 3 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const single_threaded = b.option(bool, "single-threaded", "Create a single-threaded libc implementation (default: false)") orelse false;

// check if the host has a gcc or clang available:
const maybe_gcc = b.findProgram(&.{"gcc"}, &.{}) catch null;
const maybe_clang = b.findProgram(&.{"clang"}, &.{}) catch null;

const libc = createLibrary(b, target, optimize);
libc.single_threaded = single_threaded;
b.installArtifact(libc);

for (header_files) |header_name| {
Expand Down
12 changes: 10 additions & 2 deletions src/modules/errno.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
//! implementation of `errno.h`

const std = @import("std");
const builtin = @import("builtin");

threadlocal var errno: c_int = 0;
const storage = if (builtin.single_threaded)
struct {
var errno: c_int = 0; // regular variable on single-threaded systems
}
else
struct {
threadlocal var errno: c_int = 0; // thread-local variable on multi-threaded systems
};

export fn __get_errno() *c_int {
return &errno;
return &storage.errno;
}

0 comments on commit 4c159fa

Please sign in to comment.