tether icon indicating copy to clipboard operation
tether copied to clipboard

Build failure related to C allocator

Open Morilli opened this issue 1 year ago • 8 comments

Hey, I was trying to build this using the provided makefile and ran into the following build error:

$ make
cd editor && zig build
/snap/zig/11625/lib/std/heap.zig:38:13: error: C allocator is only available when linking against libc
            @compileError("C allocator is only available when linking against libc");
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/snap/zig/11625/lib/std/c/linux.zig:295:12: error: dependency on libc must be explicitly specified in the build command
pub extern "c" fn malloc_usable_size(?*const anyopaque) usize;
           ^~~
/snap/zig/11625/lib/std/c/linux.zig:294:12: error: dependency on libc must be explicitly specified in the build command
pub extern "c" fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
           ^~~
/snap/zig/11625/lib/std/c.zig:1732:12: error: dependency on libc must be explicitly specified in the build command
pub extern "c" fn free(?*anyopaque) void;
           ^~~
make: *** [Makefile:3: zig] Error 2

I tried this on both windows and (wsl) ubuntu, but both give the same error. My zig version is 0.13.0.

Morilli avatar Sep 30 '24 23:09 Morilli

I get the same error. Might be something wrong in the build.zig file

reidiens avatar Nov 05 '24 16:11 reidiens

To get the current version to build with zig 0.13.0 you need to:

  • clone repository recursively: (add --recurse-submodules): using gh: gh repo clone zackradisic/tether -- --recurse-submodules
  • -> make sure tether/editor/src/syntax includes both tree-sitter-zig and tree-sitter-c not just empty folders - I had to manually add both submodules (just get the repositories zig c)
  • build.zig references MacOSX13.3.sdk (lines 152-154) so make sure they exist under the specified path - I had installed 15.1.sdk only, so I just edited build.zig lines 152 - 154 to reference MacOSX15.1.sdk

navigate to tether/editor and run zig build

@MARLENELASSEINPHOTOMACHEN Thank you for the help! I was able to compile it without issue.

This seems to generate the EditorKit.xcframework file. I suspected this was for the Xcode project, so I opened the project and ran it. I get the following screen below:

Screenshot 2024-11-05 at 4 48 21 PM

Do you know if this is it so far? Is there a way to demo the editor portion of the app (e.g., explosions, fun particles, etc.)?

jason5122 avatar Nov 05 '24 21:11 jason5122

Okay perfect, you're halfway there :) the editor will appear when focusing a textbox, e.g. TextEdit, and pressing cmd + shift + space

You will likely run into some issues:

  • editor/src/font.zig at line 533 creates a file at /Users/zackradisic/Code/tether/editor/atlas.bin:
    533 var file = std.fs.createFileAbsolute("/Users/zackradisic/Code/tether/editor/atlas.bin", .{}) catch @panic("OOPS"); change the path to wherever your /tether/editor/ is located.

  • tether/EditorView.swift at line 165 uses .bgra8Unorm_srgb (while editor/src/hdr.zig line 15 doesnt): change 165 view.colorPixelFormat = .bgra8Unorm_srgb
    to: 165 view.colorPixelFormat = .bgra8Unorm

  • same file tether/EditorView.swift at line 176: 176 let url = URL(fileURLWithPath: "/Users/zackradisic/Code/tether/atlas.png") change the path to your repository.

  • editor/src/font.zig at line 70 references Rec Mono Linear: 70 const iosevka = metal.NSString.new_with_bytes("Rec Mono Linear", .ascii); change that to whatever font you have installed, or download and install Recursive Mono Linear

now you should be good to go: rebuild in /editor/: zig build and start the Xcode project.


  • your xcode build might fail and prompt you to sign with your own team (just a click in the error msg)
  • tether might need permission to listen to your keyboard -> System Settings > Privacy & Security > Accessibility > Enable tether

To get the current version to build with zig 0.13.0 you need to:

* clone repository recursively: (add --recurse-submodules): _using gh:_ `gh repo clone zackradisic/tether -- --recurse-submodules`

strange -- I always call "clone" with this flag, and the dirs are still empty.

* build.zig references **MacOSX13.3.sdk** (lines 152-154) so make sure they exist under the specified path - _I had installed 15.1.sdk only, so I just edited build.zig lines 152 - 154 to reference MacOSX15.1.sdk_

Does it only work on MacOS? Haven't seen that said anywhere(

navigate to tether/editor and run zig build

Still the same error...

Musickiller avatar Nov 06 '24 06:11 Musickiller

To get the current version to build with zig 0.13.0 you need to:

  • clone repository recursively: (add --recurse-submodules): using gh: gh repo clone zackradisic/tether -- --recurse-submodules
  • -> make sure tether/editor/src/syntax includes both tree-sitter-zig and tree-sitter-c not just empty folders - I had to manually add both submodules (just get the repositories zig c)
  • build.zig references MacOSX13.3.sdk (lines 152-154) so make sure they exist under the specified path - I had installed 15.1.sdk only, so I just edited build.zig lines 152 - 154 to reference MacOSX15.1.sdk

navigate to tether/editor and run zig build

Do I just have to download and unzip the repositories for tree-sitter-zig and tree-sitter-c or do I have to use commands?

scuttyrht avatar Nov 06 '24 17:11 scuttyrht

clone repository recursively: (add --recurse-submodules): using gh: gh repo clone zackradisic/tether -- --recurse-submodules

make sure tether/editor/src/syntax includes both tree-sitter-zig and tree-sitter-c not just empty folders - I had to manually add both submodules (just get the repositories zig c)

after doing this, I'm still unable to build. I keep getting the error

/usr/lib/zig/std/heap.zig:38:13: error: C allocator is only available when linking against libc
            @compileError("C allocator is only available when linking against libc");

/usr/lib/zig/std/heap.zig:38:13: error: C allocator is only available when linking against libc
            @compileError("C allocator is only available when linking against libc");

reidiens avatar Nov 06 '24 18:11 reidiens

Okay perfect, you're halfway there :) the editor will appear when focusing a textbox, e.g. TextEdit, and pressing cmd + shift + space

You will likely run into some issues:

  • editor/src/font.zig at line 533 creates a file at /Users/zackradisic/Code/tether/editor/atlas.bin: 533 var file = std.fs.createFileAbsolute("/Users/zackradisic/Code/tether/editor/atlas.bin", .{}) catch @panic("OOPS"); change the path to wherever your /tether/editor/ is located.
  • tether/EditorView.swift at line 165 uses .bgra8Unorm_srgb (while editor/src/hdr.zig line 15 doesnt): change 165 view.colorPixelFormat = .bgra8Unorm_srgb to: 165 view.colorPixelFormat = .bgra8Unorm
  • same file tether/EditorView.swift at line 176: 176 let url = URL(fileURLWithPath: "/Users/zackradisic/Code/tether/atlas.png") change the path to your repository.
  • editor/src/font.zig at line 70 references Rec Mono Linear: 70 const iosevka = metal.NSString.new_with_bytes("Rec Mono Linear", .ascii); change that to whatever font you have installed, or download and install Recursive Mono Linear

now you should be good to go: rebuild in /editor/: zig build and start the Xcode project.

  • your xcode build might fail and prompt you to sign with your own team (just a click in the error msg)
  • tether might need permission to listen to your keyboard -> System Settings > Privacy & Security > Accessibility > Enable tether

Thank you for the help! I was able to run it (although with a few tricks which i described here https://github.com/zackradisic/tether/issues/11#issuecomment-2463855498)

iQiexie avatar Nov 07 '24 20:11 iQiexie