Skip to content

Instantly share code, notes, and snippets.

Avatar

matu3ba

  • Aachen
View GitHub Profile
@matu3ba
matu3ba / b.sh
Created Nov 24, 2022
zig-bootstrap + zig (for too old cmake version)
View b.sh
#!/usr/bin/env sh
# faster, but no stage1
/usr/bin/time -v "${HOME}/dev/git/bootstrap/zig-bootstrap/musl/out/zig-x86_64-linux-musl-native/bin/zig" build -p stage3 --search-prefix "${HOME}/dev/git/bootstrap/zig-bootstrap/musl/out/x86_64-linux-musl-native" --zig-lib-dir lib -Dstatic-llvm
# slower, but has stage1
mkdir -p build/ && cd build/ && cmake .. -DCMAKE_PREFIX_PATH="$HOME/dev/git/bootstrap/zig-bootstrap/musl/out/host/" -GNinja && /usr/bin/time -v ${HOME}/dev/git/cpp/mold/build/mold -run ninja install && cd ..
@matu3ba
matu3ba / b.sh
Last active Nov 17, 2022
build and trace helper to track down child process caching issue of Zig
View b.sh
#!/bin/sh
set -e
#echo "building debug.."
#mkdir -p build/ && cd build/ && cmake .. -DCMAKE_PREFIX_PATH="$HOME/dev/git/bootstrap/zig-bootstrap/musl/out/host/" -GNinja && /usr/bin/time -v ${HOME}/dev/git/cpp/mold/build/mold -run ninja install && cd ..
#echo "building release.."
#mkdir -p build3/ && cd build3/ && cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_PREFIX_PATH="$HOME/dev/git/bootstrap/zig-bootstrap/musl/out/host/" -GNinja && /usr/bin/time -v ${HOME}/dev/git/cpp/mold/build/mold -run ninja install && cd ..
#echo "building done"
/usr/bin/time -v "${HOME}/dev/git/bootstrap/zig-bootstrap/musl/out/zig-x86_64-linux-musl-native/bin/zig" build -p build1 --search-prefix "${HOME}/dev/git/bootstrap/zig-bootstrap/musl/out/x86_64-linux-musl-native" --zig-lib-dir lib -Dstatic-llvm &
/usr/bin/time -v "${HOME}/dev/git/bootstrap/zig-bootstrap/musl/out/zig-x86_64-linux-musl-native/bin/zig" build -p build2 -Drelease --search-prefix "${HOME}/dev/git/bootstrap/zig-bootstrap/musl/out/x86_64-linux-musl-native" --zig-li
@matu3ba
matu3ba / command_failure.sh
Created Sep 16, 2022
stage3 build error on Arch
View command_failure.sh
/home/user/dev/git/zi/zig/master/build/zig2 clang /home/user/dev/git/zi/zig/master/src/stage1/codegen.cpp -nostdinc++ -fno-caret-diagnostics -isystem /home/user/dev/git/zi/zig/master/lib/libcxx/include -isystem /home/user/dev/git/zi/zig/master/lib/libcxxabi/include -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -D_LIBCPP_HAS_NO_THREADS -D_LIBCPP_ABI_VERSION=1 -D_LIBCPP_ABI_NAMESPACE=__1 -isystem /home/user/dev/git/zi/zig/master/lib/libunwind/include -D__GLIBC_MINOR__=36 -target x86_64-unknown-linux-gnu -nostdinc -fno-spell-checking -isystem /home/user/dev/git/zi/zig/master/lib/include -isystem /usr/include -Xclang -target-cpu -Xclang x86-64 -Xclang -target-feature -Xclang -16bit-mode -Xclang -target-feature -Xclang -32bit-mode -Xclang -target-feature -Xclang -3dnow -Xclang -target-feature -Xclang -3dnowa -Xclang -target-feature -Xclang +64bit -Xclang -target-feature -Xclang -adx -Xclang -target-feature -Xclang -aes -Xclang
@matu3ba
matu3ba / notes_ropes1.md
Last active Sep 2, 2022
separate_layout_from_content
View notes_ropes1.md

Why storing accurate editor history requires to separate layout from content.

Let us understand programming as converting strings to another machine-readable or executable output with a program according to a specification (called compiler). Now let the sole layout as graphical positioning be defined by additional white spaces and newlines.

Source code formatting ensures stylistic consistency to improve readability and eases on refactoring and writing code. All formatters that enable custom user data come with an escape hatch for

@matu3ba
matu3ba / approach
Last active Aug 1, 2022
Examples for discussion on compiler meeting on 2022-08-04
View approach
Idea
1. parsing the AST to have a simplification for faster frequent access
* create another tree storing what things are active
* create another tree to store what things reference what other things for deletion strategy
(idea: no unused variable errors)
2. starting with remove stuff from end of execution to beginning and fixup unused var errors,
later graph based deletion based on where things are used (!global side effects may not be captured!)
3. rendering the used parts
* fixups will be likely dirty hacks at first
@matu3ba
matu3ba / zig_cache.md
Last active Jul 27, 2022
Big picture of the Zig caching system.
View zig_cache.md

** Big picture of the Zig caching system. ** This is a big picture of the Zig caching system, mostly motivated for me to understand the necessary bits to solve ziglang/zig#11643. It reflects the status quo of commit fcfeafe99a3ecc694a3475735c81a0d75b6da6d0. The core logic is defined in src/Cache.zig.

zig-cache/h contains the manifest files with varying content. Manifest files hold relevant data from the compilation to decide, if the files at the used paths have changed (ie from editing or git).

@matu3ba
matu3ba / child.zig
Created May 27, 2022
bench_childprocess.zig
View child.zig
const std = @import("std");
pub fn main() !void {
try std.io.getStdOut().writer().writeAll("hello world\n");
}
@matu3ba
matu3ba / fnproto_runner.zig
Created May 23, 2022
Zig simple runner through function pointer
View fnproto_runner.zig
const std = @import("std");
const builtin = @import("builtin");
const FnProto = switch (builtin.zig_backend) {
// workaround until we replace stage1 with stage2
.stage1 => ?fn (*Runner) anyerror!void,
else => ?*fn (*Runner) anyerror!void,
};
const Runner = struct {
file: std.fs.File,
@matu3ba
matu3ba / pipe.zig
Last active May 16, 2022
Pipe in Zig. Notice that EOF can only be read once child or parent close the pipe. Doesnt matter if we dup or not.
View pipe.zig
const std = @import("std");
const os = std.os;
pub fn main() !void {
const alloc = std.testing.allocator;
const pipe = try os.pipe(); // read end [0], write end [1]
const read_dup = try os.dup(pipe[0]);
const write_dup = try os.dup(pipe[1]); // for simplicity
const pid_result = try os.fork();
if (pid_result == 0) {
@matu3ba
matu3ba / canonicalize_test_unix.zig
Created May 5, 2022
path that requires canonicalization for unix and wasi
View canonicalize_test_unix.zig
test "canonicalize path Unix" {
if (builtin.os.tag == .windows) // symlinks are not portable
return error.SkipZigTest;
// TODO testing partial solution to https://github.com/ziglang/zig/issues/4812
const alloc = testing.allocator;
var tmp = testing.tmpDir(.{ .no_follow = true }); // ie zig-cache/tmp/8DLgoSEqz593PAEE
defer tmp.cleanup();
const tmpdirpath = try tmp.getFullPath(alloc);
defer alloc.free(tmpdirpath);
var cwd_buf: [fs.MAX_PATH_BYTES]u8 = undefined; // maximum size of a UTF-8 encoded file path