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)