summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--README.md18
-rw-r--r--src/main.c13
-rwxr-xr-xtests/run_tests.sh21
4 files changed, 60 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index a4dfccd..0b62685 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,7 @@
-
+# Compiler configuration
+# Default: gcc
+# To build with clang: make CC=clang
+# To build with zig: make CC="zig cc"
CC = gcc
CFLAGS = -Wall -Wextra -g -I./src -I./src/ast -I./src/parser -I./src/codegen -I./plugins -I./src/zen -I./src/utils -I./src/lexer -I./src/analysis -I./src/lsp
TARGET = zc
@@ -78,4 +81,11 @@ clean:
test: $(TARGET)
./tests/run_tests.sh
-.PHONY: all clean install uninstall test
+# Build with alternative compilers
+zig:
+ $(MAKE) CC="zig cc"
+
+clang:
+ $(MAKE) CC=clang
+
+.PHONY: all clean install uninstall test zig clang
diff --git a/README.md b/README.md
index 83b3a60..e5a6724 100644
--- a/README.md
+++ b/README.md
@@ -443,6 +443,7 @@ Zen C is designed to work with most C11 compilers. Some features rely on GNU C e
```bash
zc run app.zc --cc clang
+zc run app.zc --cc zig
```
### Test Suite Status
@@ -451,9 +452,22 @@ zc run app.zc --cc clang
|:---|:---:|:---|:---|
| **GCC** | **100%** | All Features | None. |
| **Clang** | **100%** | All Features | None. |
+| **Zig** | **100%** | All Features | None. Uses `zig cc` as a drop-in C compiler. |
| **TCC** | **~70%** | Basic Syntax, Generics, Traits | No `__auto_type`, No Intel ASM, No Nested Functions. |
-> **Recommendation:** Use **GCC** or **Clang** for production builds. TCC is excellent for rapid prototyping due to its compilation speed but misses some advanced C extensions Zen C relies on for full feature support.
+> **Recommendation:** Use **GCC**, **Clang**, or **Zig** for production builds. TCC is excellent for rapid prototyping due to its compilation speed but misses some advanced C extensions Zen C relies on for full feature support.
+
+### Building with Zig
+
+Zig's `zig cc` command provides a drop-in replacement for GCC/Clang with excellent cross-compilation support. To use Zig:
+
+```bash
+# Compile and run a Zen C program with Zig
+zc run app.zc --cc zig
+
+# Build the Zen C compiler itself with Zig
+make zig
+```
---
@@ -482,6 +496,8 @@ make test
# Run with different compiler
./tests/run_tests.sh --cc clang
+./tests/run_tests.sh --cc zig
+./tests/run_tests.sh --cc tcc
```
### Extending the Compiler
diff --git a/src/main.c b/src/main.c
index f62d635..5bd84d1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,7 +33,7 @@ void print_usage()
printf(" -o <file> Output executable name\n");
printf(" --emit-c Keep generated C file (out.c)\n");
printf(" --freestanding Freestanding mode (no stdlib)\n");
- printf(" --cc <compiler> C compiler to use (gcc, clang, tcc)\n");
+ printf(" --cc <compiler> C compiler to use (gcc, clang, tcc, zig)\n");
printf(" -O<level> Optimization level\n");
printf(" -g Debug info\n");
printf(" -v, --verbose Verbose output\n");
@@ -132,7 +132,16 @@ int main(int argc, char **argv)
{
if (i + 1 < argc)
{
- strcpy(g_config.cc, argv[++i]);
+ char *cc_arg = argv[++i];
+ // Handle "zig" shorthand for "zig cc"
+ if (strcmp(cc_arg, "zig") == 0)
+ {
+ strcpy(g_config.cc, "zig cc");
+ }
+ else
+ {
+ strcpy(g_config.cc, cc_arg);
+ }
}
}
else if (strcmp(arg, "-o") == 0)
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 8c3c7f7..8c2fbc7 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -1,5 +1,14 @@
#!/bin/bash
+# Zen-C Test Suite Runner
+# Usage: ./tests/run_tests.sh [zc options]
+#
+# Examples:
+# ./tests/run_tests.sh # Test with default compiler (gcc)
+# ./tests/run_tests.sh --cc clang # Test with clang
+# ./tests/run_tests.sh --cc zig # Test with zig cc
+# ./tests/run_tests.sh --cc tcc # Test with tcc
+
# Configuration
ZC="./zc"
TEST_DIR="tests"
@@ -7,7 +16,17 @@ PASSED=0
FAILED=0
FAILED_TESTS=""
-echo "** Running Zen C test suite **"
+# Display which compiler is being used
+CC_NAME="gcc (default)"
+for arg in "$@"; do
+ if [ "$prev_arg" = "--cc" ]; then
+ CC_NAME="$arg"
+ break
+ fi
+ prev_arg="$arg"
+done
+
+echo "** Running Zen C test suite (compiler: $CC_NAME) **"
if [ ! -f "$ZC" ]; then
echo "Error: zc binary not found. Please build it first."