From 32ff1206000f4371fde32597be72d6ab5cf964e6 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sat, 19 Nov 2022 23:53:42 +0100 Subject: [PATCH] chore: figure out how to compile everything with C --- Makefile | 3 ++- src/package/c/package.c | 2 +- src/package/package.c.v | 13 +++++++++++++ src/package/v.mod | 3 +++ src/{package => util}/c/dynarray.c | 0 src/{package => util}/c/dynarray.h | 0 src/util/util.c.v | 7 +++++++ src/util/v.mod | 3 +++ 8 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/package/package.c.v create mode 100644 src/package/v.mod rename src/{package => util}/c/dynarray.c (100%) rename src/{package => util}/c/dynarray.h (100%) create mode 100644 src/util/util.c.v create mode 100644 src/util/v.mod diff --git a/Makefile b/Makefile index e716807..5927d41 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ SRC_DIR := src SOURCES != find '$(SRC_DIR)' -iname '*.v' V_PATH ?= v -V := $(V_PATH) -showcc -gc boehm -W -d use_openssl +# We need to use GCC because TCC doesn't like the way we use C bindings +V := $(V_PATH) -showcc -gc boehm -W -d use_openssl -cc gcc all: vieter diff --git a/src/package/c/package.c b/src/package/c/package.c index a248c92..d2e3c94 100644 --- a/src/package/c/package.c +++ b/src/package/c/package.c @@ -9,7 +9,7 @@ static char *ignored_names[5] = { }; static int ignored_words_len = sizeof(ignored_names) / sizeof(char *); -inline Pkg *package_init() { +Pkg *package_init() { return calloc(sizeof(PkgInfo), 1); } diff --git a/src/package/package.c.v b/src/package/package.c.v new file mode 100644 index 0000000..a9c4784 --- /dev/null +++ b/src/package/package.c.v @@ -0,0 +1,13 @@ +module package + +#flag -I @VMODROOT/c + +// We need to specify *every* C file here. Otherwise, Vieter doesn't compile. +#flag @VMODROOT/c/package.o +#flag @VMODROOT/c/package_info.o + +#include "package.h" + +struct C.Pkg{} + +fn C.package_read_archive(pkg_path &char) &C.pkg diff --git a/src/package/v.mod b/src/package/v.mod new file mode 100644 index 0000000..dc06e78 --- /dev/null +++ b/src/package/v.mod @@ -0,0 +1,3 @@ +Module{ + name: 'package' +} diff --git a/src/package/c/dynarray.c b/src/util/c/dynarray.c similarity index 100% rename from src/package/c/dynarray.c rename to src/util/c/dynarray.c diff --git a/src/package/c/dynarray.h b/src/util/c/dynarray.h similarity index 100% rename from src/package/c/dynarray.h rename to src/util/c/dynarray.h diff --git a/src/util/util.c.v b/src/util/util.c.v new file mode 100644 index 0000000..997a18d --- /dev/null +++ b/src/util/util.c.v @@ -0,0 +1,7 @@ +module util + +#flag -I @VMODROOT/c + +// This makes the V compiler include this object file when linking, allowing +// all other C parts of the codebase to use it as well. +#flag @VMODROOT/c/dynarray.o diff --git a/src/util/v.mod b/src/util/v.mod new file mode 100644 index 0000000..39a57af --- /dev/null +++ b/src/util/v.mod @@ -0,0 +1,3 @@ +Module{ + name: 'util' +}