Build hcc from source¶
scripts/build-linux.sh --install-hcc does all of this for you. This page covers the same steps by hand, plus the options you might want to change.
Requirements¶
- Linux or macOS, on x86_64 or AArch64 (Windows: inside WSL2)
- A C compiler (
gccorclang),make,cmake,git
Clone¶
hcc changes quickly, and it's beta software. To get exactly the version these examples were tested against:
The latest master will probably work too. If it doesn't, check Compiler quirks and the upstream issue tracker before assuming your code is wrong.
Build and install¶
The top-level Makefile wraps CMake. It installs to /usr/local unless you set INSTALL_PREFIX:
make install puts three things under the prefix:
| Path | What it is |
|---|---|
bin/hcc |
the compiler |
lib/libtos.a, lib/libtos.so* |
the HolyC runtime library (strings, memory, files, hash tables, printf) |
include/tos.HH |
declarations for that library, included into every program automatically |
The prefix is compiled into hcc, which is how it finds tos.HH and libtos later. If you move them, either rebuild hcc or pass --install-dir=<prefix> on every compile.
Create the lib directory first
If <prefix>/lib doesn't exist, make install fails partway through. That's why the first command above creates it.
Build options¶
| Option | Default | Effect |
|---|---|---|
INSTALL_PREFIX |
/usr/local |
where make install puts things |
C_COMPILER |
gcc |
compiler used to build hcc itself |
BUILD_TYPE |
Release |
CMake build type; Debug to debug hcc |
-DHCC_LINK_SQLITE3=1 |
off | adds SQLite bindings to the runtime; edit the Makefile to pass it |
The JIT (hcc -jit) and the REPL (hcc -repl) are enabled by the default Makefile build.
Run hcc's own tests¶
Environment¶
hcc doesn't read any environment variables you need to set. Two things matter:
PATHmust include<prefix>/binso your shell findshcc.ccmust be onPATHat compile time. hcc calls it to assemble and link. Programs built with hcc don't need hcc orlibtosat runtime, becauselibtosis linked statically. They only need the shared C libraries they#link(SDL2, SDL2_image, GL).
Updating¶
Then rerun ./scripts/check.sh in this repo to see if anything broke.