Skip to content

Instantly share code, notes, and snippets.

@leroycep
leroycep / console
Last active May 21, 2025 04:22
A script to set the symbols from zig's compiler_rt symbols to hidden to fix issues with dynamic libraries
zig build-exe ./hide_compiler_rt.zig
./hide_compiler_rt path/to/input_lib.so path/to/output_lib.so
@leroycep
leroycep / build.zig
Created November 20, 2024 23:07
Finding symbol name from program address in EXEC type ELF files
const std = @import("std");
pub fn build(b: *std.Build) !void {
const exe = b.addExecutable(.{
.name = "symbol_from_address",
.root_source_file = b.path("./main.zig"),
.target = b.standardTargetOptions(.{}),
.optimize = b.standardOptimizeOption(.{}),
});
exe.root_module.omit_frame_pointer = false;
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
[geemili@renvi:~/src/3_resources/mach-examples]$ zig build -Drelease-safe
remote: Enumerating objects: 76, done.
remote: Counting objects: 100% (76/76), done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 67 (delta 10), reused 66 (delta 10), pack-reused 0
Unpacking objects: 100% (67/67), 387.14 KiB | 1.22 MiB/s, done.
From https://github.com/hexops/sdk-linux-x86_64
b65ab86..1cb61f5 main -> origin/main
downloading https://github.com/hexops/mach-gpu-dawn/releases/download/release-dd770e7/libdawn_x86_64-linux-gnu_release-fast.a.gz..
% Total % Received % Xferd Average Speed Time Time Time Current

Emscripten as a linker for Zig and C

This shows how to build a nontrivial program using Zig+Emscripten or C+Emscripten. In both cases Emscripten is only used as a linker, that is the frontend is either zig or clang.

"Nontrivial" here means the program uses interesting Emscripten features:

  • Asyncify
  • Full GLES3 support
  • GLFW3 support
@leroycep
leroycep / gist:c25d3aecca59b6b0e743af3a9f8db97e
Created October 23, 2022 19:44
`zig build run-triangle -Drelease-safe` error output
LLD Link... ld.lld: warning: /home/geemili/src/3_resources/mach-examples/zig-cache/mach/gpu-dawn/release-c68d8cd/x86_64-linux-gnu/release-fast/libdawn.a: archive member '/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/zig-cache/o/3782c3161961accaf3f066311d258554/libglfw.a' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/geemili/src/3_resources/mach-examples/zig-cache/mach/gpu-dawn/release-c68d8cd/x86_64-linux-gnu/release-fast/libdawn.a: archive member '/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/zig-cache/o/3782c3161961accaf3f066311d258554/libglfw.a' is neither ET_REL nor LLVM bitcode
ld.lld: error: undefined symbol: internal_load_libgamemode
>>> referenced by cimport.zig:737 (/home/geemili/src/3_resources/mach-examples/zig-cache/o/a53156978d47df309a631246da168b16/cimport.zig:737)
>>> lto.tmp:(main)
>>> referenced by cimport.zig:723 (/home/geemili/src/3_resources/mach-examples/zig-cache/o/a53156978d47df309a631246da168b16/cimport.zig:723)
>>> lto.tmp:(main)
>>> referenced
@leroycep
leroycep / gist:dac1e02bb0bb27a4ef9da896b57e8c82
Last active August 7, 2022 23:27
mach game compile error
downloading https://github.com/hexops/mach-gpu-dawn/releases/download/release-fbb4741/libdawn_x86_64-linux-gnu_debug.a.gz..
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 77.4M 100 77.4M 0 0 8970k 0 0:00:08 0:00:08 --:--:-- 13.2M
downloading https://github.com/hexops/mach-gpu-dawn/releases/download/release-fbb4741/headers.json.gz..
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 46762 100 46762 0 0 37047 0 0:00:01 0:00:01 --:--:-- 97k
@leroycep
leroycep / flake.nix
Created July 14, 2022 00:18
zig development environment flake
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
zig-master = {
url = "github:jessestricker/zig-master.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
@leroycep
leroycep / qute-add-todoist.nu
Created July 5, 2022 02:02
A qutebrowser userscript for quickly adding tasks to todoist
#!/usr/bin/env nu
let SECRETS_FILE = ([$env.QUTE_CONFIG_DIR "qute-add-todoist.secrets"] | path join)
if not (echo $SECRETS_FILE | path exists) {
qute $'message-error "Could not find secrets file! Copy the API token into ($SECRETS_FILE)""'
qute 'open -t https://todoist.com/app/settings/integrations'
exit
}
const Errors = error{
hello,
world,
};
// It's a tagged union, expect the tag is an error set
const ErrorUnion = union(Errors) {
hello: u32,
world: []const u8,
};