Skip to content

Commit 718f291

Browse files
remorseskommander
andauthored
Upgrade to Zig 0.15.2 (#439)
--------- Co-authored-by: Sebastian <[email protected]>
1 parent a423905 commit 718f291

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2221
-3057
lines changed

.github/workflows/build-core.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build:
1010
name: Core - Build and Test
11-
runs-on: ubuntu-latest
11+
runs-on: macos-latest
1212
steps:
1313
- name: Checkout code
1414
uses: actions/checkout@v4
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Zig
2222
uses: goto-bus-stop/setup-zig@v2
2323
with:
24-
version: 0.14.1
24+
version: 0.15.2
2525

2626
- name: Install dependencies
2727
run: bun install

.github/workflows/build-native.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
default: false
1515

1616
env:
17-
ZIG_VERSION: 0.14.1
17+
ZIG_VERSION: 0.15.2
1818

1919
jobs:
2020
build-native:
@@ -39,7 +39,10 @@ jobs:
3939
run: bun install
4040

4141
- name: Build packages (cross-compile for all platforms)
42-
run: bun run build
42+
run: |
43+
cd packages/core
44+
bun run build:native --all
45+
bun run build:lib
4346
4447
- name: Verify build outputs
4548
run: |

.github/workflows/build-react.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Zig
2222
uses: goto-bus-stop/setup-zig@v2
2323
with:
24-
version: 0.14.1
24+
version: 0.15.2
2525

2626
- name: Install dependencies
2727
run: bun install

.github/workflows/build-solid.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Zig
2222
uses: goto-bus-stop/setup-zig@v2
2323
with:
24-
version: 0.14.1
24+
version: 0.15.2
2525

2626
- name: Install dependencies
2727
run: bun install

.github/workflows/npm-release.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Setup Zig
2727
uses: goto-bus-stop/setup-zig@v2
2828
with:
29-
version: 0.14.1
29+
version: 0.15.2
3030

3131
- name: Extract version from tag
3232
id: extract_version
@@ -52,8 +52,13 @@ jobs:
5252
- name: Prepare release versions
5353
run: bun run prepare-release "${{ steps.version_scheme.outputs.version }}"
5454

55-
- name: Build packages
56-
run: bun run build
55+
- name: Build packages (cross-compile for all platforms)
56+
run: |
57+
cd packages/core
58+
bun run build:native --all
59+
bun run build:lib
60+
cd ../solid && bun run build
61+
cd ../react && bun run build
5762
5863
- name: Publish packages
5964
run: bun run publish

.zig-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.14.1
1+
0.15.2

packages/core/scripts/build.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const args = process.argv.slice(2)
4040
const buildLib = args.find((arg) => arg === "--lib")
4141
const buildNative = args.find((arg) => arg === "--native")
4242
const isDev = args.includes("--dev")
43+
const buildAll = args.includes("--all") // Build for all platforms
4344

4445
const variants: Variant[] = [
4546
{ platform: "darwin", arch: "x64" },
@@ -78,16 +79,17 @@ if (missingRequired.length > 0) {
7879
}
7980

8081
if (buildNative) {
81-
console.log(`Building native ${isDev ? "dev" : "prod"} binaries...`)
82+
console.log(`Building native ${isDev ? "dev" : "prod"} binaries${buildAll ? " for all platforms" : ""}...`)
8283

83-
const zigBuild: SpawnSyncReturns<Buffer> = spawnSync(
84-
"zig",
85-
["build", `-Doptimize=${isDev ? "Debug" : "ReleaseFast"}`],
86-
{
87-
cwd: join(rootDir, "src", "zig"),
88-
stdio: "inherit",
89-
},
90-
)
84+
const zigArgs = ["build", `-Doptimize=${isDev ? "Debug" : "ReleaseFast"}`]
85+
if (buildAll) {
86+
zigArgs.push("-Dall")
87+
}
88+
89+
const zigBuild: SpawnSyncReturns<Buffer> = spawnSync("zig", zigArgs, {
90+
cwd: join(rootDir, "src", "zig"),
91+
stdio: "inherit",
92+
})
9193

9294
if (zigBuild.error) {
9395
console.error("Error: Zig is not installed or not in PATH")
@@ -124,16 +126,10 @@ if (buildNative) {
124126
}
125127

126128
if (copiedFiles === 0) {
127-
console.error(`Error: No dynamic libraries found for ${platform}-${arch} in ${libDir}`)
128-
console.error(`Expected to find files like: libopentui.so, libopentui.dylib, opentui.dll`)
129-
console.error(`Found files in ${libDir}:`)
130-
if (existsSync(libDir)) {
131-
const files = spawnSync("ls", ["-la", libDir], { stdio: "pipe" })
132-
if (files.stdout) console.error(files.stdout.toString())
133-
} else {
134-
console.error("Directory does not exist")
135-
}
136-
process.exit(1)
129+
// Skip platforms that weren't built
130+
console.log(`Skipping ${platform}-${arch}: no libraries found`)
131+
rmSync(nativeDir, { recursive: true, force: true })
132+
continue
137133
}
138134

139135
const indexTsContent = `const module = await import("./${libraryFileName}", { with: { type: "file" } })

packages/core/src/renderables/Code.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,16 @@ test("CodeRenderable - streaming with conceal and drawUnstyledText=false should
16921692

16931693
currentRenderer.root.add(codeRenderable)
16941694

1695+
const waitForHighlightingCycle = async (timeout = 2000) => {
1696+
const start = Date.now()
1697+
await renderOnce()
1698+
await new Promise((resolve) => setTimeout(resolve, 10))
1699+
while (codeRenderable.isHighlighting && Date.now() - start < timeout) {
1700+
await new Promise((resolve) => setTimeout(resolve, 10))
1701+
}
1702+
await renderOnce()
1703+
}
1704+
16951705
// Use TestRecorder to capture frames
16961706
const { TestRecorder } = await import("../testing/test-recorder")
16971707
const recorder = new TestRecorder(currentRenderer)
@@ -1701,13 +1711,13 @@ test("CodeRenderable - streaming with conceal and drawUnstyledText=false should
17011711
recorder.rec()
17021712

17031713
// Wait for initial highlighting to complete
1704-
await new Promise((resolve) => setTimeout(resolve, 100))
1714+
await waitForHighlightingCycle()
17051715

17061716
// Now simulate streaming: add more content including fenced code block
17071717
codeRenderable.content = `# Example\n\nHere's some code:\n\n\`\`\`typescript\nconst x = 1;\n\`\`\``
17081718

17091719
// Wait for highlighting to process the update
1710-
await new Promise((resolve) => setTimeout(resolve, 150))
1720+
await waitForHighlightingCycle()
17111721

17121722
// Stop everything
17131723
currentRenderer.stop()

packages/core/src/tests/wrap-resize-perf.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,16 @@ describe("Word wrap algorithmic complexity", () => {
176176
const widths = [60, 70, 80, 90, 100]
177177
const times: number[] = []
178178

179-
view.setWrapWidth(widths[0])
180-
view.measureForDimensions(widths[0], 100)
179+
// Warmup
180+
view.setWrapWidth(50)
181+
view.measureForDimensions(50, 100)
181182

183+
// Measure first (uncached) call for each width
182184
for (const width of widths) {
183185
view.setWrapWidth(width)
184-
const time = measureMedian(() => {
185-
view.measureForDimensions(width, 100)
186-
})
187-
times.push(time)
186+
const start = performance.now()
187+
view.measureForDimensions(width, 100)
188+
times.push(performance.now() - start)
188189
}
189190

190191
view.destroy()

packages/core/src/zig/ansi.zig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ pub const ANSI = struct {
2121

2222
// Direct writing to any writer - the most efficient option
2323
pub fn moveToOutput(writer: anytype, x: u32, y: u32) AnsiError!void {
24-
std.fmt.format(writer, "\x1b[{d};{d}H", .{ y, x }) catch return AnsiError.WriteFailed;
24+
writer.print("\x1b[{d};{d}H", .{ y, x }) catch return AnsiError.WriteFailed;
2525
}
2626

2727
pub fn fgColorOutput(writer: anytype, r: u8, g: u8, b: u8) AnsiError!void {
28-
std.fmt.format(writer, "\x1b[38;2;{d};{d};{d}m", .{ r, g, b }) catch return AnsiError.WriteFailed;
28+
writer.print("\x1b[38;2;{d};{d};{d}m", .{ r, g, b }) catch return AnsiError.WriteFailed;
2929
}
3030

3131
pub fn bgColorOutput(writer: anytype, r: u8, g: u8, b: u8) AnsiError!void {
32-
std.fmt.format(writer, "\x1b[48;2;{d};{d};{d}m", .{ r, g, b }) catch return AnsiError.WriteFailed;
32+
writer.print("\x1b[48;2;{d};{d};{d}m", .{ r, g, b }) catch return AnsiError.WriteFailed;
3333
}
3434

3535
// Text attribute constants
@@ -51,11 +51,11 @@ pub const ANSI = struct {
5151
pub const cursorUnderlineBlink = "\x1b[3 q";
5252

5353
pub fn cursorColorOutputWriter(writer: anytype, r: u8, g: u8, b: u8) AnsiError!void {
54-
std.fmt.format(writer, "\x1b]12;#{x:0>2}{x:0>2}{x:0>2}\x07", .{ r, g, b }) catch return AnsiError.WriteFailed;
54+
writer.print("\x1b]12;#{x:0>2}{x:0>2}{x:0>2}\x07", .{ r, g, b }) catch return AnsiError.WriteFailed;
5555
}
5656

5757
pub fn explicitWidthOutput(writer: anytype, width: u32, text: []const u8) AnsiError!void {
58-
std.fmt.format(writer, "\x1b]66;w={d};{s}\x1b\\", .{ width, text }) catch return AnsiError.WriteFailed;
58+
writer.print("\x1b]66;w={d};{s}\x1b\\", .{ width, text }) catch return AnsiError.WriteFailed;
5959
}
6060

6161
pub const resetCursorColor = "\x1b]112\x07";
@@ -131,12 +131,15 @@ pub const ANSI = struct {
131131
pub const setTerminalTitle = "\x1b]0;{s}\x07";
132132

133133
pub fn setTerminalTitleOutput(writer: anytype, title: []const u8) AnsiError!void {
134-
std.fmt.format(writer, setTerminalTitle, .{title}) catch return AnsiError.WriteFailed;
134+
writer.print(setTerminalTitle, .{title}) catch return AnsiError.WriteFailed;
135135
}
136136

137137
pub fn makeRoomForRendererOutput(writer: anytype, height: u32) AnsiError!void {
138138
if (height > 1) {
139-
writer.writeByteNTimes('\n', height - 1) catch return AnsiError.WriteFailed;
139+
var i: u32 = 0;
140+
while (i < height - 1) : (i += 1) {
141+
writer.writeByte('\n') catch return AnsiError.WriteFailed;
142+
}
140143
}
141144
}
142145
};

0 commit comments

Comments
 (0)