Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ compiler/package.yaml
compiler/acton/acton.cabal
compiler/acton/package.yaml
compiler/lib/package.yaml
compiler/lib/libacton.cabal
compiler/lsp-server/package.yaml
compiler/lsp-server/lsp-server-acton.cabal
test/package.yaml
Expand Down
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ CXX=$(ZIG) c++
export CC
export CXX

# We use Zig CC & C++ for doing Stack / GHC builds
STACK=CC="tools/zig-cc.sh" CXX="tools/zig-cxx.sh" CFLAGS= ACTON_REAL_LD="$(TD)/compiler/tools/zig-cc.sh" stack --with-gcc=$(TD)/compiler/tools/zig-cc.sh

# Determine which xargs we have. BSD xargs does not have --no-run-if-empty,
# rather, it is the default behavior so the argument is superfluous. We check if
# we are using GNU xargs by trying to run xargs --version and grep for 'GNU', if
Expand Down Expand Up @@ -65,6 +68,8 @@ endif
# -- Linux ---------------------------------------------------------------------
ifeq ($(shell uname -s),Linux)
OS:=linux
ACTON_ZIG_GLIBC_VERSION ?= 2.31
export ACTON_ZIG_GLIBC_VERSION
ifeq ($(shell uname -m),x86_64)
ACTONC_TARGET := --target x86_64-linux-gnu.2.27
else ifeq ($(shell uname -m),aarch64)
Expand Down Expand Up @@ -118,17 +123,15 @@ test-backend: $(BACKEND_TESTS)
# /compiler ----------------------------------------------
ACTONC_HS=$(wildcard compiler/lib/src/*.hs compiler/lib/src/*/*.hs compiler/acton/*.hs compiler/acton/*/*.hs)
ACTONLSP_HS=$(wildcard compiler/lsp-server/*.hs)
# NOTE: we're unsetting CC & CXX to avoid using zig cc & zig c++ for stack /
# ghc, which doesn't seem to work properly
dist/bin/acton: compiler/lib/package.yaml.in compiler/acton/package.yaml.in compiler/lsp-server/package.yaml.in compiler/stack.yaml $(ACTONC_HS) $(ACTONLSP_HS) version.mk
mkdir -p dist/bin
rm -f dist/bin/actonc
cd compiler && sed 's,^version: BUILD_VERSION,version: "$(VERSION)",' < lib/package.yaml.in > lib/package.yaml
cd compiler && unset CC && unset CXX && unset CFLAGS && stack build acton lsp-server-acton --dry-run 2>&1 | grep "Nothing to build" || \
cd compiler && $(STACK) build acton lsp-server-acton --dry-run 2>&1 | grep "Nothing to build" || \
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add dist/zig dependency for compiler target

dist/bin/acton now invokes $(STACK) at this line, and $(STACK) is defined to use compiler/tools/zig-cc.sh/zig-cxx.sh, which abort when dist/zig/zig is not present. Because the target prerequisites still do not include $(DIST_ZIG), running make dist/bin/acton directly (or in a parallel flow that has not built Zig yet) can fail nondeterministically before the build starts; declaring the Zig artifact as an explicit prerequisite would make this target reliable.

Useful? React with 👍 / 👎.

(sed 's,^version: BUILD_VERSION,version: "$(VERSION_INFO)",' < acton/package.yaml.in > acton/package.yaml \
&& sed 's,^version: BUILD_VERSION,version: "$(VERSION_INFO)",' < lsp-server/package.yaml.in > lsp-server/package.yaml \
&& stack build acton lsp-server-acton $(STACK_OPTS) --ghc-options='-j4 $(ACTC_GHC_OPTS)')
cd compiler && unset CC && unset CXX && unset CFLAGS && stack --local-bin-path=../dist/bin install acton lsp-server-acton
&& $(STACK) build acton lsp-server-acton $(STACK_OPTS) --ghc-options='-j4 $(ACTC_GHC_OPTS)')
cd compiler && $(STACK) --local-bin-path=../dist/bin install acton lsp-server-acton
# Keep actonc as a symlink for compatibility
ln -sf acton dist/bin/actonc

Expand Down
6 changes: 4 additions & 2 deletions compiler/acton/package.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ executables:
- -optl-no-pie
- -pgml=../tools/ld-wrapper.sh
- condition: os(linux) && !arch(aarch64)
ld-options:
- -static
ghc-options:
- -no-pie
- -optl-no-pie
- -pgml=../tools/ld-wrapper.sh

tests:
test_acton:
Expand Down
6 changes: 4 additions & 2 deletions compiler/lsp-server/package.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ executables:
- -optl-no-pie
- -pgml=../tools/ld-wrapper.sh
- condition: os(linux) && !arch(aarch64)
ld-options:
- -static
ghc-options:
- -no-pie
- -optl-no-pie
- -pgml=../tools/ld-wrapper.sh
2 changes: 1 addition & 1 deletion compiler/tools/ld-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ state="static"
arch="$(uname -m 2>/dev/null || true)"
allow_dynamic_glibc=false
case "$arch" in
aarch64|arm64)
aarch64|arm64|x86_64|amd64)
allow_dynamic_glibc=true
;;
esac
Expand Down
65 changes: 65 additions & 0 deletions compiler/tools/zig-cc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env sh
set -eu

SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
ROOT_DIR="$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)"
ZIG_BIN="$ROOT_DIR/dist/zig/zig"

if [ ! -x "$ZIG_BIN" ]; then
echo "error: expected Zig at $ZIG_BIN; run 'make dist/zig' first" >&2
exit 1
fi

has_explicit_target=false
expect_target_arg=false
for arg in "$@"; do
if [ "$expect_target_arg" = true ]; then
has_explicit_target=true
expect_target_arg=false
continue
fi

case "$arg" in
-target)
expect_target_arg=true
;;
-target=*)
has_explicit_target=true
;;
--target)
expect_target_arg=true
;;
--target=*)
has_explicit_target=true
;;
esac
done

if [ "$(uname -s 2>/dev/null || true)" = "Linux" ] \
&& [ -n "${ACTON_ZIG_GLIBC_VERSION:-}" ] \
&& [ "$has_explicit_target" = false ]; then
zig_host_target="$("$ZIG_BIN" env 2>/dev/null | awk -F'"' '/\.target = "/ {print $2; exit}')"
if [ -z "$zig_host_target" ]; then
echo "error: failed to derive Zig host target from '$ZIG_BIN env'" >&2
exit 1
fi

case "$zig_host_target" in
*-gnu*)
;;
*)
echo "error: requested ACTON_ZIG_GLIBC_VERSION but host target '$zig_host_target' is not GNU libc based" >&2
exit 1
;;
esac

zig_host_arch="${zig_host_target%%-*}"
if [ -z "$zig_host_arch" ]; then
echo "error: failed to derive host architecture from Zig target '$zig_host_target'" >&2
exit 1
fi

exec "$ZIG_BIN" cc -target "$zig_host_arch-linux-gnu.${ACTON_ZIG_GLIBC_VERSION}" "$@"
fi

exec "$ZIG_BIN" cc "$@"
65 changes: 65 additions & 0 deletions compiler/tools/zig-cxx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env sh
set -eu

SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
ROOT_DIR="$(CDPATH= cd -- "$SCRIPT_DIR/../.." && pwd)"
ZIG_BIN="$ROOT_DIR/dist/zig/zig"

if [ ! -x "$ZIG_BIN" ]; then
echo "error: expected Zig at $ZIG_BIN; run 'make dist/zig' first" >&2
exit 1
fi

has_explicit_target=false
expect_target_arg=false
for arg in "$@"; do
if [ "$expect_target_arg" = true ]; then
has_explicit_target=true
expect_target_arg=false
continue
fi

case "$arg" in
-target)
expect_target_arg=true
;;
-target=*)
has_explicit_target=true
;;
--target)
expect_target_arg=true
;;
--target=*)
has_explicit_target=true
;;
esac
done

if [ "$(uname -s 2>/dev/null || true)" = "Linux" ] \
&& [ -n "${ACTON_ZIG_GLIBC_VERSION:-}" ] \
&& [ "$has_explicit_target" = false ]; then
zig_host_target="$("$ZIG_BIN" env 2>/dev/null | awk -F'"' '/\.target = "/ {print $2; exit}')"
if [ -z "$zig_host_target" ]; then
echo "error: failed to derive Zig host target from '$ZIG_BIN env'" >&2
exit 1
fi

case "$zig_host_target" in
*-gnu*)
;;
*)
echo "error: requested ACTON_ZIG_GLIBC_VERSION but host target '$zig_host_target' is not GNU libc based" >&2
exit 1
;;
esac

zig_host_arch="${zig_host_target%%-*}"
if [ -z "$zig_host_arch" ]; then
echo "error: failed to derive host architecture from Zig target '$zig_host_target'" >&2
exit 1
fi

exec "$ZIG_BIN" c++ -target "$zig_host_arch-linux-gnu.${ACTON_ZIG_GLIBC_VERSION}" "$@"
fi

exec "$ZIG_BIN" c++ "$@"
2 changes: 2 additions & 0 deletions docs/acton-dev-guide/src/getting_started/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ dist/bin/actonc path/to/file.act # compatibility alias
## Caching and build knobs

- `ZIG_LOCAL_CACHE_DIR` controls Zig's cache location (defaults to `~/.cache/acton/zig-local-cache` when `HOME` is set).
- Stack uses `compiler/tools/zig-cc.sh` / `compiler/tools/zig-cxx.sh` so GHC/Cabal go through `dist/zig/zig`.
- On Linux, set `ACTON_ZIG_GLIBC_VERSION=<major.minor>` to force Zig CC/C++ wrappers to pass `-target <host-arch>-linux-gnu.<major.minor>` (for example `2.35`).
- `BUILD_RELEASE=1 make` stamps release versions; default builds get a timestamped version suffix.
- On Linux, the Makefile pins the default target to glibc 2.27 for compatibility.
Loading