Zig is an imperative, general-purpose, statically typed, compiled system programming language designed by Andrew Kelley. It’s intended to be a successor to the C programming language, with the goals of being even smaller and simpler to program in while also offering modern features, new optimizations and a variety of safety mechanisms while not as demanding of runtime safety as seen in other languages. Zig is available for free to download from https://ziglang.org/

Zig is to C what Rust is to C++, and I wondered if it could be used a drop-in replacement for gcc with R.

Add to .R/Makevars:

CFLAGS +=             -O3 -Wall -pipe -pedantic -std=gnu99
CXXFLAGS +=           -O3 -Wall -pipe -Wno-unused -pedantic 

CC = zig cc
CXX = zig c++
CXXSTD = zig c++
CXX98 = zig c++
CXX11 = zig c++
CXX14 = zig c++
CXX17 = zig c++
CXX20 = zig c++
CXXCPP = zig c++
OBJC = zig cc
OBJCXX = zig c++
SHLIB_CXXLD = zig c++

MAKE = make -j4

If Zig is installed via homebrew on MacOS, the path may need adding to the R environment:

old_path <- Sys.getenv("PATH")

Sys.setenv(PATH = paste(old_path, "/opt/homebrew/bin", sep = ":"))
© 2024 Steve Checkley