Skip to content

Commit

Permalink
Builds are now almost zero dependency
Browse files Browse the repository at this point in the history
Just need make, bash, curl and zlib1g-dev
  • Loading branch information
ingydotnet committed Nov 4, 2023
1 parent 19944c3 commit c831d0d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .rc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ YAMLSCRIPT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd -P)
[[ :$PATH: == *:"$YAMLSCRIPT_ROOT/install/bin":* ]] ||
PATH=$YAMLSCRIPT_ROOT/install/bin:$PATH

[[ :$LD_LIBRARY_PATH: == *:"$YAMLSCRIPT_ROOT/install/lib":* ]] ||
LD_LIBRARY_PATH=$YAMLSCRIPT_ROOT/install/lib:$PATH

# XXX This goes away after perl binding to libyamlscript is implemented.
[[ :$PATH: == *:"$YAMLSCRIPT_ROOT/perl/bin":* ]] ||
PATH=$YAMLSCRIPT_ROOT/perl/bin:$PATH
Expand All @@ -13,6 +16,7 @@ YAMLSCRIPT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd -P)
PYTHONPATH=$YAMLSCRIPT_ROOT/python/lib

export \
LD_LIBRARY_PATH \
PATH \
PYTHONPATH \
YAMLSCRIPT_ROOT \
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ chown:
$(BUILD):
build: $(BUILD)
build-%: %
-$(MAKE) -C $< build
$(MAKE) -C $< build

install-local: install/bin/ys install/lib/libyamlscript.$(SO)
install/bin/ys: ys/ys install/bin
Expand Down
4 changes: 2 additions & 2 deletions clojure/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export PATH := $(ROOT)/clojure/bin:$(PATH)
#------------------------------------------------------------------------------
build:: $(YAMLSCRIPT_CORE_INSTALLED)

install test:
lein $@
install test: $(LEIN)
$< $@

Dockerfile:: $(COMMON) Makefile
cat \
Expand Down
44 changes: 30 additions & 14 deletions common/clojure.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ifneq (,$(findstring linux,$(ostype)))
$(error Unsupported Linux MACHTYPE: $machtype)
endif

else ifneq (,$(findstring darwin,$(ostype)))
else ifeq (true,$(IS_MACOS))
GRAALVM_SUBDIR := /Contents/Home

ifneq (,$(findstring arm64-apple-darwin,$(machtype)))
Expand Down Expand Up @@ -57,6 +57,7 @@ endif

GRAALVM_HOME := $(GRAALVM_PATH)$(GRAALVM_SUBDIR)
GRAALVM_DOWNLOAD := /tmp/$(GRAALVM_TAR)
GRAALVM_INSTALLED := $(GRAALVM_HOME)/release

GRAALVM_O ?= 1

Expand All @@ -71,6 +72,9 @@ ifdef w
export WARN_ON_REFLECTION := 1
endif

LEIN := $(BUILD_BIN)/lein
LEIN_URL := https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein

LEIN_COMMANDS := \
check \
classpath \
Expand Down Expand Up @@ -105,12 +109,22 @@ clean:: nrepl-stop
distclean::
$(RM) -r .calva/ .clj-kondo/ .cpcache/ .lsp/ .vscode/ .portal/

$(LEIN): $(BUILD_BIN) $(GRAALVM_INSTALLED)
ifeq (,$(CURL))
$(error *** 'curl' is required but not installed)
endif
$(CURL) -L -o $@ $(LEIN_URL)
chmod +x $@

$(BUILD_BIN):
mkdir -p $@

# Leiningen targets
$(LEIN_COMMANDS)::
lein $@
$(LEIN_COMMANDS):: $(LEIN)
$< $@

deps-graph::
lein deps :tree
deps-graph:: $(LEIN)
$< deps :tree

# Build/GraalVM targets
force:
Expand All @@ -119,20 +133,22 @@ force:
$(YAMLSCRIPT_CORE_INSTALLED): $(YAMLSCRIPT_CORE_SRC)
$(MAKE) -C ../clojure install

graalvm:: $(GRAALVM_PATH)

$(GRAALVM_PATH): $(GRAALVM_DOWNLOAD)
$(GRAALVM_INSTALLED): $(GRAALVM_DOWNLOAD)
tar xzf $<
mv graalvm-* $@
mv graalvm-* $(GRAALVM_PATH)
touch $@

$(GRAALVM_DOWNLOAD):
curl -L -o $@ $(GRAALVM_URL)
ifeq (,$(CURL))
$(error *** 'curl' is required but not installed)
endif
$(CURL) -L -o $@ $(GRAALVM_URL)

# REPL/nREPL management targets
repl:: repl-deps
repl:: $(LEIN) repl-deps
ifneq (,$(wildcard .nrepl-pid))
@echo "Connecting to nREPL server on port $$(< .nrepl-port)"
lein repl :connect
$< repl :connect
endif

repl-deps::
Expand All @@ -156,9 +172,9 @@ ifdef PORT
repl-port := :port $(PORT)
endif

.nrepl-pid:
.nrepl-pid: $(LEIN)
( \
lein repl :headless $(repl-port) & \
$< repl :headless $(repl-port) & \
echo $$! > $@ \
)
@( \
Expand Down
23 changes: 20 additions & 3 deletions common/vars.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
BUILD_BIN := /tmp/yamlscript/bbin

COMMON := $(ROOT)/common

export PATH := $(ROOT)/bin:$(PATH)
export PATH := $(ROOT)/bin:$(BUILD_BIN):$(PATH)

export YAMLSCRIPT_ROOT ?= $(ROOT)

Expand All @@ -12,22 +14,37 @@ ostype := $(shell /bin/bash -c 'echo $$OSTYPE')
machtype := $(shell /bin/bash -c 'echo $$MACHTYPE')

ifneq (,$(findstring linux,$(ostype)))
IS_LINUX := true
GCC := gcc -std=gnu99 -fPIC -shared
SO := so
DY :=
else ifneq (,$(findstring darwin,$(ostype)))
IS_MACOS := true
GCC := gcc -dynamiclib
SO := dylib
DY := DY
else
$(error Unsupported OSTYPE: $(ostype))
endif

IS_ROOT :=
IS_ROOT ?= undefined
ifneq (false,$(IS_ROOT))
ifeq (0,$(shell id -u))
IS_ROOT := true
IS_ROOT := true
endif
endif

LIBZ := false
ifeq (true,$(IS_MACOS))
LIBZ := true
else
ifneq (,$(shell ldconfig -p | grep $$'^\tlibz.$(SO) '))
LIBZ := true
endif
endif

CURL := $(shell command -v curl)

LIBRARY_PATH := $(ROOT)/libyamlscript/lib
export $(DY)LD_LIBRARY_PATH := $(LIBRARY_PATH)
LIBYAMLSCRIPT_SO_PATH := $(LIBRARY_PATH)/libyamlscript.$(SO)
Expand Down
12 changes: 9 additions & 3 deletions libyamlscript/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ repl-deps:: $(LIBYAMLSCRIPT_JAR_PATH)

distclean::

$(LIBYAMLSCRIPT_SO_PATH): $(LIBYAMLSCRIPT_JAR_PATH) $(GRAALVM_PATH)
$(LIBYAMLSCRIPT_SO_PATH): $(GRAALVM_INSTALLED) $(LIBYAMLSCRIPT_JAR_PATH)
ifneq (true,$(LIBZ))
$(error *** The 'libz.$(SO)' library is required by native-image but not installed)
endif
mkdir -p $(dir $@)
# The next command may take a long time (a minute or so)
time \
Expand All @@ -60,9 +63,12 @@ $(LIBYAMLSCRIPT_SO_PATH): $(LIBYAMLSCRIPT_JAR_PATH) $(GRAALVM_PATH)

ifeq (true,$(IS_ROOT))
$(LIBYAMLSCRIPT_JAR_PATH):
ifeq (true,$(IS_ROOT))
$(error *** YAMLScript 'make build' must be run as non-root user)
endif
else
$(LIBYAMLSCRIPT_JAR_PATH): $(YAMLSCRIPT_CORE_INSTALLED) $(GRAALVM_PATH)
lein uberjar
$(LIBYAMLSCRIPT_JAR_PATH): $(LEIN) $(YAMLSCRIPT_CORE_INSTALLED)
$< uberjar
endif

Dockerfile:: $(COMMON) Makefile
Expand Down
9 changes: 6 additions & 3 deletions ys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ jar: $(YAMLSCRIPT_CLI_JAR_PATH)
test: $(YAMLSCRIPT_CLI_BIN)
./test.sh

$(YAMLSCRIPT_CLI_BIN): $(YAMLSCRIPT_CLI_JAR_PATH) $(GRAALVM_PATH)
$(YAMLSCRIPT_CLI_BIN): $(YAMLSCRIPT_CLI_JAR_PATH)
ifneq (true,$(LIBZ))
$(error *** The 'libz.$(SO)' library is required by native-image but not installed)
endif
mkdir -p $(dir $@)
time \
native-image \
Expand Down Expand Up @@ -56,8 +59,8 @@ distclean::
ifeq (true,$(IS_ROOT))
$(YAMLSCRIPT_CLI_JAR_PATH):
else
$(YAMLSCRIPT_CLI_JAR_PATH): $(YAMLSCRIPT_CORE_INSTALLED) $(YAMLSCRIPT_CLI_SRC)
lein uberjar
$(YAMLSCRIPT_CLI_JAR_PATH): $(LEIN) $(YAMLSCRIPT_CORE_INSTALLED) $(YAMLSCRIPT_CLI_SRC)
$< uberjar
endif

Dockerfile:: $(COMMON) Makefile
Expand Down

0 comments on commit c831d0d

Please sign in to comment.