authorgravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-05-27 13:34:48-07:00
committergravatar for me@paperdave.netdave caruso <me@paperdave.net> 2024-05-27 13:34:48-07:00
logdeeaeceb25e046541a6e42d49c4e51226dca9660
tree070de6858c5b6ebb4bfbe3db64f9c6f73a60aedc
parent74ce0c381324aeb3b73bb9928bcf433ee7e0e687
signature Commit is signed but in an unrecognized format.

add build script


4 files changed, 97 insertions(+), 2 deletions(-)

README.md+4-1
...@@ -6,6 +6,10 @@ This language is a mix of features from JavaScript, Rust, and Zig. Some notable...@@ -6,6 +6,10 @@ This language is a mix of features from JavaScript, Rust, and Zig. Some notable
6- **Zig** - Execute any code at compile time, everything is an expression.6- **Zig** - Execute any code at compile time, everything is an expression.
7- **JavaScript** - Garbage collected values with a versitile type system.7- **JavaScript** - Garbage collected values with a versitile type system.
88
9## Developing
10
11To compile a development build, one can use the provided `./build` or `.\build.cmd` scripts to download Zig and build the compiler. These scripts are effective aliases of `zig build`. A release build can be built by passing the `--release` flag to any of these commands.
12
9## Standard Library13## Standard Library
1014
11Currently, there is no standard library. One will be introduced later.15Currently, there is no standard library. One will be introduced later.
...@@ -79,4 +83,3 @@ var number: float = 0; // `number` is `float`...@@ -79,4 +83,3 @@ var number: float = 0; // `number` is `float`
79```83```
8084
81## Functions85## Functions
82
build created+53
...@@ -0,0 +1,53 @@
1#!/bin/sh
2# This script will build the compiler on any POSIX system.
3# It automatically installs a Zig compiler to ./zig-cache
4# if needed. The output will be in ./zig-out/bin.
5#
6# `curl` and `tar` is required in order to download and
7# extract Zig, respectively. The rest of the dependencies
8# are downloaded compiled using the Zig build system.
9cd -- "$(dirname -- "$0")"
10
11ZIG_VERSION=$(grep .minimum_zig_version build.zig.zon \
12 | cut -d '"' -f 2)
13
14ZIG="zig-cache/zig/$ZIG_VERSION/zig"
15if [ ! -f "$ZIG" ]; then
16 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
17 if [ "$OS" = "darwin" ]; then
18 OS="macos"
19 fi
20 ARCH=$(uname -m)
21 if [ "$ARCH" = "arm64" ]; then
22 ARCH="aarch64"
23 fi
24
25 URL="https://ziglang.org/builds/zig-$OS-$ARCH-$ZIG_VERSION.tar.xz"
26
27 echo "Installing Zig v$ZIG_VERSION via $URL"
28
29 CURL=$(command -v curl 2>/dev/null)
30 TAR=$(command -v curl 2>/dev/null)
31
32 if [ -z "$CURL" ]; then
33 echo "This script requires 'curl' to be installed."
34 fi
35 if [ -z "$TAR" ]; then
36 echo "This script requires 'tar' to be installed."
37 fi
38
39 if [ -z "$CURL" ] || [ -z "$TAR" ]; then
40 exit 1
41 fi
42
43 mkdir -p zig-cache/zig/$ZIG_VERSION
44 curl -fsSL --retry 3 --retry-delay 3 $URL \
45 | tar -xJ --strip-components=1 -C zig-cache/zig/$ZIG_VERSION
46 if [ "$($ZIG version)" != "$ZIG_VERSION" ]; then
47 echo "Zig failed to install."
48 rm -rf zig-cache/zig/$ZIG_VERSION
49 exit 1
50 fi
51fi
52
53$ZIG build $@
build.cmd created+29
...@@ -0,0 +1,29 @@
1@ECHO OFF
2@REM This script will build the compiler on any Windows system
3@REM It automatically installs a Zig compiler to ./zig-cache
4@REM The output will be in ./zig-out/bin
5
6SET ROOT=%~dp0
7FOR /F "tokens=3 delims=, " %%i IN (
8 'FINDSTR /R "\.minimum_zig_version *= *""".+""",\n" ^
9 "%ROOT%build.zig.zon"'
10) DO SET ZIG_VERSION=%%i
11SET ZIG_VERSION=%ZIG_VERSION:~1,-1%
12IF NOT EXIST "%ROOT%zig-cache\zig\%ZIG_VERSION%\zig.exe" GOTO :find_powershell
13:build
14"%ROOT%zig-cache\zig\%ZIG_VERSION%\zig.exe" build %*
15EXIT /b %ERRORLEVEL%
16:find_powershell
17FOR %%i IN (pwsh powershell) DO WHERE %%i /Q && SET PS=%%i && GOTO :download
18ECHO Powershell not found. Please install it and try again.
19EXIT /b 1
20:download
21SET ZIG_ARCH=x86_64
22SET URI=https://ziglang.org/builds/zig-windows-%ZIG_ARCH%-%ZIG_VERSION%.zip
23SET X=$null = New-Item -ItemType Directory -Force -Path zig-cache\zig
24SET X=%X%;Invoke-RestMethod -Uri %URI% -OutFile zig-cache/zig-%ZIG_VERSION%.zip
25SET X=%X%;Expand-Archive zig-cache/zig-%ZIG_VERSION%.zip -DestinationPath zig-cache/zig
26SET X=%X%;Remove-Item zig-cache/zig-%ZIG_VERSION%.zip
27%PS% -NoProfile -Command "%X%"
28MOVE zig-cache\zig\zig-windows-%ZIG_ARCH%-%ZIG_VERSION% zig-cache\zig\%ZIG_VERSION% >NUL
29GOTO :build
build.zig+11-1
...@@ -7,7 +7,17 @@ pub fn build(b: *std.Build) void {...@@ -7,7 +7,17 @@ pub fn build(b: *std.Build) void {
7 b.reference_trace = 20;7 b.reference_trace = 20;
88
9 const target = b.standardTargetOptions(.{});9 const target = b.standardTargetOptions(.{});
10 const optimize = b.standardOptimizeOption(.{});10 const optimize_fallback = b.standardOptimizeOption(.{});
11 const optimize: std.builtin.OptimizeMode = switch (b.release_mode) {
12 .off => optimize_fallback,
13 .safe => .ReleaseSafe,
14 .fast => .ReleaseFast,
15 .small => .ReleaseSmall,
16 .any => brk: {
17 b.release_mode = .safe;
18 break :brk .ReleaseSafe;
19 },
20 };
1121
12 const tracing = b.option(enum {22 const tracing = b.option(enum {
13 none,23 none,