Skip to content

Instantly share code, notes, and snippets.

View kassane's full-sized avatar
🏠
Working from home

Matheus C. França kassane

🏠
Working from home
View GitHub Profile
../zig-bootstrap/out/zig-x86_64-linux-musl-baseline/zig build -Dtarget=native-native-msvc -DBUILD_SHARED_LIBS=true -Ddisable_handle_fork=false -Denable_cplusplus=true -Denable_gc_assertions=true -Denable_gc_debug=true -Denable_large_config=false -Denable_munmap=true -Denable_parallel_mark=false -Denable_redirect_malloc=false -Denable_rwlock=true -Denable_thread_local_alloc=true -Denable_threads=true -Denable_werror test -fwine
steps [5/43] zig build-exe initfromthreadtest Debug native-native-msvc... Created 205 threads (174 ended)
GC_check_heap_block: found 1 smashed heap objects:
0x79c926ed4db8 in or near object at 0x79c926ed4d90 (/app/bdwgc/tests/smash.c:34, sz= 40)
Call chain at allocation:
steps [12/43] zig build-exe realloctest Debug native-native-msvc... Heap size: 65536
Heap size: 131072
sh: 1: /usr/bin/addr2line: not found
/app/bdwgc/zig-cache/o/ed2c75516bbcd33b227e2d90c7f211f1/libgc.so(+0x4596b) [0x79c9272a596b]
/app/bdwgc/zig-cache/o/ed2c75516bbcd33b227e2d90c
@kassane
kassane / bdwgc.supp
Last active April 29, 2024 13:57
BoehmGC based on `std::pmr::memory_resource`
{
<insert_a_suppression_name_here>
Memcheck:Cond
fun:GC_push_all_eager
fun:GC_with_callee_saves_pushed
fun:UnknownInlinedFun
fun:GC_push_roots.lto_priv.0
fun:GC_mark_some
fun:GC_stopped_mark
fun:GC_try_to_collect_inner.lto_priv.0
@kassane
kassane / Dockerfile
Created April 1, 2024 20:14
Modm.io - C++ modern for embedded - STM32
# Based on: https://modm.io/guide/installation/
FROM ubuntu:latest
RUN apt-get update && \
apt-get install -y \
python3 \
python3-pip \
scons \
cmake \
@kassane
kassane / builtin_cnl.zig
Last active March 26, 2024 14:15
zig esp32 (espressif llvm backend)
const std = @import("std");
/// Zig version. When writing code that supports multiple versions of Zig, prefer
/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks.
pub const zig_version = std.SemanticVersion.parse(zig_version_string) catch unreachable;
pub const zig_version_string = "0.12.0-dev.xtensa.2858+8e52bb152";
pub const zig_backend = std.builtin.CompilerBackend.stage2_llvm;
pub const output_mode = std.builtin.OutputMode.Obj;
pub const link_mode = std.builtin.LinkMode.Static;
pub const is_test = false;
@kassane
kassane / main.zig
Last active February 16, 2024 20:14
zig build to PSVita target
// replacing https://github.com/vitasdk/samples/blob/master/hello_world/src/main.c
const c = @cImport({
@cInclude("psp2/kernel/processmgr.h");
@cInclude("psp2/kernel/threadmgr.h");
@cInclude("stdio.h");
@cInclude("debugScreen.h");
@cDefine("printf", "psvDebugScreenPrintf");
});
pub export fn main() c_int {
@kassane
kassane / gdextension_interface.zig
Last active December 29, 2023 17:13
Godot 4 - GDExtension for zig bindings
// GDExtension - zig (v0.11.0 or master) binding
// cmd: godot --dump-gdextension-interface -q --headless
// based on: https://github.com/godot-dlang/godot-dlang/blob/master/gdextension_interface.h
const std = @import("std");
pub const GDExtensionVariantType = enum(c_uint) {
GDEXTENSION_VARIANT_TYPE_NIL = 0,
GDEXTENSION_VARIANT_TYPE_BOOL = 1,
GDEXTENSION_VARIANT_TYPE_INT = 2,
GDEXTENSION_VARIANT_TYPE_FLOAT = 3,

Named arguments in D language

DIP1030

Named/labeled/keyword arguments are useful in Python and OCaml, but in the D language they were proposed by DIP1030 and adopted three years ago.

Currently, templates are not supported, but recent DMDs -preview allow you to try out these features without any flags. The verification environment this time is DMD2.106.0.

module intrusive_mpsc_queue;
import core.atomic;
// An intrusive MPSC queue in D.
struct IntrusiveQueue(T)
{
private T* head;
private T* tail;
private T stub;
@kassane
kassane / dlang_UEFI_Boot.md
Last active December 7, 2023 12:55
Running D language with Zephyr

Development environment

  • LDC
  • lld
  • qemu
  • ovmf(Open Virtual Machine Firmware)

Also, although it is not required, I use just as the command runner, just like the reference source. Make is fine, but I felt like I could understand the FAQ's philosophy, so I tried using it.

UEFI target

@kassane
kassane / ldc2_zig_cc.sh
Last active November 4, 2023 15:10
LDC2 cross-compiling using zig toolchain - D language
#!/usr/bin/env bash
# Based on: https://github.com/kassane/xwin-zig-test/
# download and unpack WinSDK and MSCRT libs
# manifest 16 == VS2019
# xwin --manifest-version 16 --accept-license splat --output $PWD/.xwin --include-debug-symbols --preserve-ms-arch-notation --include-debug-libs
# "$HOME/ldc-xcross/lib64" - need prebuilded libs
# curl -LO https://github.com/ldc-developers/ldc/releases/download/v1.35.0/ldc2-1.35.0-windows-multilib.7z