navid/haze / commit

d6acf09bc499

Navid M <navidmomtahen@gmail.com> · 2026-12-02

parents: 01a056cbc8ae

Browse files at this commit · Download source

build: use cmake instead
--- /dev/null+++ b/CMakeLists.txt@@ -0,0 +1,94 @@+cmake_minimum_required(VERSION 3.20)+project(haze VERSION 0.0.1 LANGUAGES C CXX)++set(CMAKE_C_STANDARD 99)+set(CMAKE_C_STANDARD_REQUIRED ON)+set(CMAKE_CXX_STANDARD 23)+set(CMAKE_CXX_STANDARD_REQUIRED ON)+set(CMAKE_CXX_EXTENSIONS OFF)++# UQBE is pinned to a commit and archive checksum so builds do not depend on a+# sibling checkout or on the system curl/tar tools.+set(UQBE_REV "9f2f2d35c3c6ec7eb0f8fa81de1941eb9097a11e" CACHE STRING "UQBE revision")+set(UQBE_SHA256 "a5d36e2e59a5a24f30bd8b8158a716aa2dc5c553b8e2bf5d568828018349b254"+    CACHE STRING "UQBE archive SHA-256")+set(UQBE_DIR "" CACHE PATH "Existing UQBE source directory")++if(NOT UQBE_DIR AND DEFINED ENV{UQBE_DIR})+    set(UQBE_DIR "$ENV{UQBE_DIR}")+endif()++if(UQBE_DIR)+    if(NOT EXISTS "${UQBE_DIR}/libqbe.h")+        message(FATAL_ERROR "UQBE_DIR does not contain libqbe.h: ${UQBE_DIR}")+    endif()+else()+    set(UQBE_PARENT "${CMAKE_BINARY_DIR}/_deps")+    set(UQBE_ARCHIVE "${UQBE_PARENT}/uqbe-${UQBE_REV}.tar.gz")+    set(UQBE_DIR "${UQBE_PARENT}/uqbe-${UQBE_REV}")+    if(NOT EXISTS "${UQBE_DIR}/libqbe.h")+        set(_uqbe_hash "")+        if(EXISTS "${UQBE_ARCHIVE}")+            file(SHA256 "${UQBE_ARCHIVE}" _uqbe_hash)+        endif()+        if(NOT _uqbe_hash STREQUAL "${UQBE_SHA256}")+            file(MAKE_DIRECTORY "${UQBE_PARENT}")+            file(DOWNLOAD+                "https://github.com/navid-m/uqbe/archive/${UQBE_REV}.tar.gz"+                "${UQBE_ARCHIVE}"+                EXPECTED_HASH "SHA256=${UQBE_SHA256}"+                TLS_VERIFY ON+                TIMEOUT 120+                STATUS _uqbe_status)+            list(GET _uqbe_status 0 _uqbe_code)+            if(NOT _uqbe_code EQUAL 0)+                list(GET _uqbe_status 1 _uqbe_error)+                file(REMOVE "${UQBE_ARCHIVE}")+                message(FATAL_ERROR "failed to download UQBE: ${_uqbe_error}")+            endif()+        endif()+        file(ARCHIVE_EXTRACT INPUT "${UQBE_ARCHIVE}" DESTINATION "${UQBE_PARENT}")+        if(NOT EXISTS "${UQBE_DIR}/libqbe.h")+            message(FATAL_ERROR "UQBE archive did not contain libqbe.h")+        endif()+    endif()+endif()++set(UQBE_SOURCE_NAMES+    libqbe.c abi.c alias.c cfg.c copy.c emit.c fold.c gcm.c getopt.c gvn.c+    ifopt.c live.c load.c mem.c parse.c rega.c simpl.c spill.c ssa.c util.c+    amd64/targ.c amd64/sysv.c amd64/isel.c amd64/emit.c amd64/winabi.c+    arm64/targ.c arm64/abi.c arm64/isel.c arm64/emit.c+    rv64/targ.c rv64/abi.c rv64/isel.c rv64/emit.c)++set(UQBE_SOURCES)+foreach(source IN LISTS UQBE_SOURCE_NAMES)+    list(APPEND UQBE_SOURCES "${UQBE_DIR}/${source}")+endforeach()++add_library(hazert STATIC runtime/hazert.cpp)+target_include_directories(hazert PUBLIC runtime)+if(MSVC)+    target_compile_options(hazert PRIVATE /EHs-c- /GR-)+else()+    target_compile_options(hazert PRIVATE -fno-exceptions -fno-rtti)+endif()++add_executable(hz+    src/codegen.cpp+    src/driver.cpp+    src/lexer.cpp+    src/parser.cpp+    src/sema.cpp+    src/types.cpp+    ${UQBE_SOURCES})+target_include_directories(hz PRIVATE+    src+    "${UQBE_DIR}"+    "${UQBE_DIR}/amd64"+    "${UQBE_DIR}/arm64"+    "${UQBE_DIR}/rv64")+target_link_libraries(hz PRIVATE hazert)++add_executable(hazert_test EXCLUDE_FROM_ALL tests/runtime_test.cpp)+target_link_libraries(hazert_test PRIVATE hazert)--- a/src/driver.cpp+++ b/src/driver.cpp@@ -226,7 +226,7 @@                 return fs::weakly_canonical(p, ec).string();         }     }-    throw std::runtime_error("cannot find libhazert.a; build it with xmake or pass -runtime path");+    throw std::runtime_error("cannot find libhazert.a; build it with CMake or pass -runtime path"); }  std::string find_cc(const Options& o) {--- a/xmake.lua+++ /dev/null@@ -1,90 +0,0 @@-add_rules("mode.debug", "mode.release")-set_languages("c99", "c++23")---- UQBE is pinned to a commit so builds do not depend on a sibling checkout.-local uqbe_url = "https://github.com/navid-m/uqbe"-local uqbe_rev = "9f2f2d35c3c6ec7eb0f8fa81de1941eb9097a11e"-local uqbe_sources = {-    "libqbe.c", "abi.c", "alias.c", "cfg.c", "copy.c", "emit.c", "fold.c",-    "gcm.c", "getopt.c", "gvn.c", "ifopt.c", "live.c", "load.c", "mem.c",-    "parse.c", "rega.c", "simpl.c", "spill.c", "ssa.c", "util.c",-    "amd64/targ.c", "amd64/sysv.c", "amd64/isel.c", "amd64/emit.c",-    "amd64/winabi.c", "arm64/targ.c", "arm64/abi.c", "arm64/isel.c",-    "arm64/emit.c", "rv64/targ.c", "rv64/abi.c", "rv64/isel.c", "rv64/emit.c"-}---- The Haze runtime: static archive linked into every produced executable.-target("hazert")-    set_kind("static")-    set_default(true)-    add_files("runtime/*.cpp")-    add_includedirs("runtime")-    if is_plat("windows") and is_toolchain("msvc") then-        add_cxxflags("/EHs-c-", "/GR-")-    else-        add_cxxflags("-fno-exceptions", "-fno-rtti")-    end-target("hazert_test")-    set_kind("binary")-    set_default(false)-    add_files("tests/runtime_test.cpp")-    add_includedirs("runtime")-    add_deps("hazert")---- The Haze compiler.  UQBE is compiled in as a library; main.c is replaced by--- libqbe.c from the pinned UQBE revision.-target("hz")-    set_kind("binary")-    set_default(true)-    add_files("src/*.cpp")-    add_includedirs("src")-    on_load(function (target)-        local uqbe_dir = os.getenv("UQBE_DIR")-        if not uqbe_dir then-            uqbe_dir = path.join(os.projectdir(), ".xmake", "deps",-                                 "uqbe-" .. uqbe_rev:sub(1, 12))-            if not os.isfile(path.join(uqbe_dir, "libqbe.h")) then-                os.mkdir(uqbe_dir)-                local archive = path.join(os.tmpdir(),-                                          "haze-uqbe-" .. uqbe_rev .. ".tar.gz")-                if not os.isfile(archive) then-                    local url = uqbe_url .. "/archive/" .. uqbe_rev .. ".tar.gz"-                    local ok = try {-                        function ()-                            return os.execv("curl", {"-fsSL", url, "-o", archive})-                        end-                    }-                    if not ok then-                        ok = try {-                            function ()-                                return os.execv("wget", {"-q", "-O", archive, url})-                            end-                        }-                    end-                    if not ok then-                        raise("cannot download UQBE from " .. url ..-                              "; install curl or wget, or set UQBE_DIR")-                    end-                end-                local ok = try {-                    function ()-                        return os.execv("tar", {"-xzf", archive, "-C", uqbe_dir,-                                                "--strip-components=1"})-                    end-                }-                if not ok or not os.isfile(path.join(uqbe_dir, "libqbe.h")) then-                    raise("cannot extract the UQBE archive; set UQBE_DIR " ..-                          "to an existing UQBE checkout")-                end-            end-        elseif not os.isfile(path.join(uqbe_dir, "libqbe.h")) then-            raise("UQBE_DIR does not contain libqbe.h: " .. uqbe_dir)-        end-        for _, source in ipairs(uqbe_sources) do-            target:add("files", path.join(uqbe_dir, source))-        end-        target:add("includedirs", uqbe_dir,-                   path.join(uqbe_dir, "amd64"),-                   path.join(uqbe_dir, "arm64"),-                   path.join(uqbe_dir, "rv64"))-    end)