Repository navigation
Adds a Zig stdlib compatibility layer so zpdf builds on both Zig 0.15.x and Zig 0.16.0. #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e1309aa
feat: adding a compatibility layer for zig 0.15 and 0.16 stdlib API c…
trvon ff8d560
fix: addressing code rabbit and github copilot review notes
trvon 67fe58b
fix: coderabbit follow up fix
trvon 62f3414
ci: test supported Zig versions
Lulzx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Zig ${{ matrix.zig-version }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| zig-version: | ||
| - 0.15.2 | ||
| - 0.16.0 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Zig | ||
| uses: mlugg/setup-zig@v2 | ||
| with: | ||
| version: ${{ matrix.zig-version }} | ||
|
|
||
| - name: Run tests | ||
| run: zig build test | ||
|
|
||
| - name: Build native targets | ||
| run: zig build | ||
|
|
||
| - name: Build WebAssembly target | ||
| run: zig build wasm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| const std = @import("std"); | ||
| const compat = @import("src/compat.zig"); | ||
| const testpdf = @import("src/testpdf.zig"); | ||
|
|
||
| pub fn main() !void { | ||
| var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
| var gpa = compat.generalPurposeAllocator(); | ||
| defer _ = gpa.deinit(); | ||
| const allocator = gpa.allocator(); | ||
|
|
||
| // Zig 0.16 file I/O requires an Io implementation. Keep this local to the | ||
| // standalone generator instead of adopting the richer process.Init entrypoint. | ||
| var threaded: if (@hasDecl(std.process, "Init")) std.Io.Threaded else void = if (@hasDecl(std.process, "Init")) .init(allocator, .{}) else {}; | ||
| defer if (@hasDecl(std.process, "Init")) threaded.deinit(); | ||
| if (@hasDecl(std.process, "Init")) compat.setIo(threaded.io()); | ||
|
|
||
| const pdf_data = try testpdf.generateMinimalPdf(allocator, "Hello from zpdf!"); | ||
| defer allocator.free(pdf_data); | ||
|
|
||
| const file = try std.fs.cwd().createFile("test.pdf", .{}); | ||
| defer file.close(); | ||
| try file.writeAll(pdf_data); | ||
| const file = try compat.createFileCwd("test.pdf"); | ||
| defer compat.closeFile(file); | ||
| try compat.writeAllFile(file, pdf_data); | ||
|
|
||
| std.debug.print("Generated test.pdf ({} bytes)\n", .{pdf_data.len}); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bufferis not deinitialized ifextractTextfails (catch return null). If any bytes were appended before the error, this leaks memory fromc_allocator. Add anerrdefer buffer.deinit(c_allocator);after initialization (and keep the currenttoOwnedSliceownership transfer on success).