221 points · by whatever3 · 2y ago · 123 comments
I was wondering why it was under a different github site.
We embed TinyCC for FFI, but TinyCC doesn't expose a way to read the types for exported symbols.
Currently, it looks like this:
import { dlopen, FFIType, suffix } from "bun:ffi";
// `suffix` is either "dylib", "so", or "dll" depending on the platform
// you don't have to use "suffix", it's just there for convenience
const path = `libsqlite3.${suffix}`;
const {
symbols: {
sqlite3_libversion, // the function to call
},
} = dlopen(
path, // a library name or file path
{
sqlite3_libversion: {
// no arguments, returns a string
args: [],
returns: FFIType.cstring,
},
},
);
console.log(`SQLite 3 version: ${sqlite3_libversion()}`);
It would be nicer if it was something like this: import {sqlite3_libversion as version} from "sqlite3.h" with {lib: "sqlite3"};
console.log(`SQLite 3 version: ${version()}`);
Would love to use Aro to do this in the future import sqlite3;
This causes sqlite3.h to be read, lexed, parsed, and semantically analyzed to convert (where possible) C symbols to D symbols, and makes them available to the importer.I've been sometimes pressured to instead use various more complicated syntaxes, but have held the line :-)
import c = sqlite3;
On that topic, i wish it was possible to group named imports, perhaps this way: import c = sqlite3, miniz; new_clib("/system/lib64/liblog.so", "log")
ffi.cdef[[int __android_log_print(int priority, const char *tag, const char *msg);]]
ffi.log.__android_log_print(5, "TEST_TAG", "Hello from FFI")
I can't say I'm familiar with Bun, but I've used a similar syntax to the example you provided of the current Bun syntax when working with Frida (https://frida.re). I agree it leaves something to be desired and indeed it would be cool if Aro could do this in the future.[1] https://repo.or.cz/luajit-2.0.git/blob/HEAD:/src/lj_cparse.c
dmd hello.c
./hello
hello world
This helps enormously in binding to existing C libraries.What conclusion should we draw about Aro based on what you’re saying?
The post title is "Aro, Zig's new C compiler", not just about Aro or Zig. In fact, just by virtue of being about Aro, it is also about C compilers - as the title clearly says, whether you (pedantically) like it or not. And D is a language that is used as a better C too, apart from other things. In fact, lang C -> lang D, says something significant to this discussion, right?
>Could you draw a comparison for those who came here for Zig and not D?
Sigh.
More pedantic talk.
Shall we start drawing Venn diagrams to clarify things?
Is it not possible that there can be different groups of people, some of whom are interested in Zig, others in Zig and Aro, others in C compilers generally, and others in D with some of those groups overlapping? That's what Venn diagrams are meant to show.
Generally speaking, the more you stray from the most concrete topic at hand (in this case Aro and only Aro), the more it becomes appropriate to explain and elaborate on the relation between that and whatever you've decided to talk about instead. In my view, anyway.
D would deserve attention too, in a separate post, or here if it was explained how it relates to Aro.
Last I tried, I found some compiler options and commands to do it, but they were badly explained, I tried for hours and it just didn't work at all, so I gave up.
I am currently adding AArch64 support to DMD's code generator. dmd doesn't run on my Raspberry Pi (yet!), so I use sshfs to access the Pi's filesystem from Ubuntu, compile programs on Ubuntu, transfer the .o file to the Pi, link it on the Pi, and run it on the Pi.
I'm sorry you're having trouble with this, so I recommend posting on the D forums, and people are there to help!
Zig is notable for putting a lot of work into hard-coding basic C libraries, though of course you still need a scattering of other C libraries for most real-world programs.
(for a sufficiently advanced language ecosystem, the language's own libraries should be easy enough)
- get a suitable cross compiler toolchain
- pick whether you want dynamic or static linking (most likely static when the target system does not come with /nix/store)
- compile all prerequisites for the library such as transitive dependencies
- compile the library with the cross compiler for the selected target arch
All in one command line call, that does not require you to 'apt-get install' any of the tools manually:
nix-build '<nixpkgs>' -A pkgsStatic.libpng --arg crossSystem '{ config = "armv7a-unknown-linux-gnueabihf"; }'What I need to work reliably from C++ are 1. instantiation of imported templates, ideally including CRTP, and 2. handling in D of exceptions thrown from C++, because if I use a C++ library that throws, I need to be able to handle the exception.
So far I’ve found languages that can import template classes and functions from C++ (usually by extending LLVM/Clang), but no languages that have good, reliable cross-platform C++ exception handling.
Also, do you know when the changes Andrew mentioned in his "Data Oriented Design" are going to be released in the zig compiler?
I would expect that when both of the above are done, compiling Zig will be really, really fast compared to anything we currently have.
https://github.com/ziglang/zig/issues?q=is%3Aissue+is%3Aopen...
Am I understanding correctly that this is a regular C compiler used as a component of the Zig compiler chain allowing compilation of C files alongside Zig? Or does Zig generate C and therefore need a C compiler under the hood?
Looking at the documentation suggests it is the former, not the latter.
I also started reading through the Zig overview [1] and near the end of that document it says this: "Not only can Zig compile C code, but there is a very good reason to use Zig as a C compiler: Zig ships with libc."
From the doc, IIUC, compilation of header files and other C code allows Zig to do direct interop with no intermediaries. Seems useful.
I guess since you said header, you keep everything opaque and create a header for that which gets translated to Zig.
Note that it's the dependency which is being eliminated: it will remain possible to use LLVM as a back end, and to compile Zig and C together without using Aro to translate the C into Zig. If I'm understanding the roadmap correctly, the C headers needed to link a C library with Zig code will be translated into Zig, but doing so with the actual .c files will be optional.
I have a lot of prior C usage background, including for nontrivial stuff, including a product, although it has been a while since I used it.
and I am checking out zig as one of my next languages to learn in the C-like / systems programming area.
To be honest PL market feels similar to consumer market where gadgets with myriad smart features sell more than plain but solid machines.
I needed a regex library for another project, and dashed off an acceptable one in a week flat https://github.com/mnemnion/mvzr
The fun part about this is that it can compile, and match, during both comptime and runtime. Will it replace PCRE? No. But nor is it intended to.
It lures people in with “use any allocator you want”! Which only appears as freedom of choice when reality it’s locking the user into the same paradigm of memory management that has given C a bad name to begin with.
What is the value proposition of this compiler, then?
Zig helps a lot, but in comparison, Aro is small, and simple to understand and maintain.
What about quaternions, or vectors and matrices of sizes 2-4 at least?
Is there any real advantage over just using a struct?
Would MultiArrayList help with performance for complex numbers and vectors?
complex32/64/128, quaternion64/128/256
https://odin-lang.org/docs/overview/#array-programming
https://odin-lang.org/docs/overview/#matrix-type
Probably helps it's the language JangaFX uses for their products used by essentially every major video game, movie, and TV show out there (https://jangafx.com/#headline-603-384)
main.c:1:10: fatal error: 'stdio.h' not found
#include <stdio.h>
It'd be nice if header inclusion, and -l options work. This would allow benchmarking Aro against some other compilers on a wide range of C files. Usually sqlite3.c is my first go-to for stress-testing C compilers. arocc -fsyntax-only -Wno-unknown-attributes sqlite3.c- why create a competing front end to Zig?
- what problems is it solving?
- what’s different than the official Zig frontend?
Etc