Skip to content

Commit 2bd0dc5

Browse files
committed
Cleanup build
1 parent 4ccd51a commit 2bd0dc5

File tree

8 files changed

+69
-68
lines changed

8 files changed

+69
-68
lines changed

.github/workflows/build-gems.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,17 @@ jobs:
6262
steps:
6363
- uses: actions/checkout@v4
6464

65-
- name: Add LLVM apt Repo
66-
run: |-
67-
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
68-
sudo add-apt-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-21 main"
69-
sudo apt update
70-
71-
- name: Install APT dependencies
72-
run: xargs sudo apt-get install -y --no-install-recommends < Aptfile
73-
7465
- name: Setup Ruby
7566
uses: ruby/setup-ruby@v1
7667
with:
77-
bundler-cache: false
78-
79-
- name: bundle install
80-
run: bundle install
68+
ruby-version: '3.4'
69+
bundler-cache: true
8170

8271
- name: Render Templates
8372
run: bundle exec rake templates
8473

85-
- name: Compile Herb
86-
run: bundle exec rake make
74+
- name: Vendor Prism
75+
run: bundle exec rake prism:vendor
8776

8877
- name: Build gem
8978
run: |
@@ -128,7 +117,7 @@ jobs:
128117
uses: ruby/setup-ruby@v1
129118
with:
130119
ruby-version: '3.4'
131-
bundler-cache: false
120+
bundler-cache: true
132121

133122
- name: Download gem artifacts
134123
uses: actions/download-artifact@v4

.github/workflows/build.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,11 @@ jobs:
3838
with:
3939
bundler-cache: true
4040

41-
- name: bundle install
42-
run: bundle install
43-
4441
- name: Render Templates
4542
run: bundle exec rake templates
4643

4744
- name: Compile Herb
48-
run: bundle exec rake make
45+
run: make
4946

5047
- name: Compile Ruby extension
5148
run: bundle exec rake compile
@@ -63,7 +60,7 @@ jobs:
6360
# run: bundle exec srb tc
6461

6562
- name: Run C tests
66-
run: ./run_herb_tests
63+
run: make test && ./run_herb_tests
6764

6865
- name: Run valgrind on examples/
6966
run: ./bin/valgrind_check_examples

.github/workflows/java.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ jobs:
3636
- name: Compile Herb
3737
run: bundle exec rake make
3838

39-
- name: Build JNI library
40-
run: make jni
41-
working-directory: java
42-
43-
- name: Compile Java classes
44-
run: make java
39+
- name: Build JNI library and Java classes
40+
run: make all
4541
working-directory: java
4642

4743
- name: Run tests

.github/workflows/rust.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ jobs:
4444
with:
4545
bundler-cache: true
4646

47-
- name: bundle install
48-
run: bundle install
49-
5047
- name: Render Templates
5148
run: bundle exec rake templates
5249

5350
- name: Compile Herb
5451
run: bundle exec rake make
5552

53+
- name: Build Rust
54+
run: make build
55+
working-directory: rust
56+
5657
- name: Check Rust formatting
5758
run: make format-check
5859
working-directory: rust
@@ -61,10 +62,6 @@ jobs:
6162
run: make lint
6263
working-directory: rust
6364

64-
- name: Build Rust
65-
run: make build
66-
working-directory: rust
67-
6865
- name: Run Rust tests
6966
run: make test
7067
working-directory: rust

Makefile

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ extension_sources = $(wildcard ext/**/*.c)
99
extension_headers = $(wildcard ext/**/*.h)
1010
extension_objects = $(extension_sources:.o)
1111

12-
prism_objects = $(filter-out src/main.c, $(sources))
13-
1412
project_files = $(sources) $(headers)
1513
extension_files = $(extension_sources) $(extension_headers)
1614
nodejs_extension_files = $(wildcard node/**/*.cpp) $(wildcard node/**/*.h) $(wildcard node/**/*.hpp)
@@ -30,12 +28,15 @@ $(shell mkdir -p $(build_dir))
3028

3129
os := $(shell uname -s)
3230

33-
prism_path = $(shell bundle show prism)
34-
prism_include = $(prism_path)/include
35-
prism_build = $(prism_path)/build
31+
prism_vendor_path = vendor/prism
32+
prism_include = $(prism_vendor_path)/include
33+
prism_src = $(prism_vendor_path)/src
34+
35+
prism_sources = $(wildcard $(prism_src)/*.c) $(wildcard $(prism_src)/util/*.c)
36+
prism_objects = $(prism_sources:.c=.o)
37+
prism_static_lib = $(build_dir)/libprism.a
3638

37-
prism_flags = -I$(prism_include)
38-
prism_ldflags = $(prism_build)/libprism.a
39+
prism_flags = -I$(prism_include) -I$(prism_src)
3940

4041
# Enable strict warnings
4142
warning_flags = -Wall -Wextra -Werror -pedantic
@@ -60,7 +61,7 @@ shared_flags = $(production_flags) $(shared_library_flags) $(prism_flags)
6061

6162
ifeq ($(os),Linux)
6263
test_cflags = $(test_flags) -I/usr/include/check
63-
test_ldflags = -L/usr/lib/x86_64-linux-gnu -lcheck -lm -lsubunit $(prism_ldflags)
64+
test_ldflags = -L/usr/lib/x86_64-linux-gnu -lcheck -lm -lsubunit
6465
cc = clang-21
6566
clang_format = clang-format-21
6667
clang_tidy = clang-tidy-21
@@ -69,7 +70,7 @@ endif
6970
ifeq ($(os),Darwin)
7071
brew_prefix := $(shell brew --prefix check)
7172
test_cflags = $(test_flags) -I$(brew_prefix)/include
72-
test_ldflags = -L$(brew_prefix)/lib -lcheck -lm $(prism_ldflags)
73+
test_ldflags = -L$(brew_prefix)/lib -lcheck -lm
7374
llvm_path = $(shell brew --prefix llvm@21)
7475
cc = $(llvm_path)/bin/clang
7576
clang_format = $(llvm_path)/bin/clang-format
@@ -78,30 +79,40 @@ endif
7879

7980
all: templates prism $(exec) $(lib_name) $(static_lib_name) test wasm clangd_config
8081

81-
$(exec): $(objects)
82-
$(cc) $(objects) $(flags) $(ldflags) $(prism_ldflags) -o $(exec)
82+
$(exec): $(objects) $(prism_objects)
83+
$(cc) $(objects) $(prism_objects) $(flags) $(ldflags) -o $(exec)
8384

84-
$(lib_name): $(objects)
85-
$(cc) -shared $(objects) $(shared_flags) $(ldflags) $(prism_ldflags) -o $(lib_name)
85+
$(lib_name): $(objects) $(prism_objects)
86+
$(cc) -shared $(objects) $(prism_objects) $(shared_flags) $(ldflags) -o $(lib_name)
8687
# cp $(lib_name) $(ruby_extension)
8788

8889
$(static_lib_name): $(objects)
8990
ar rcs $(static_lib_name) $(objects)
9091

92+
$(prism_static_lib): $(prism_objects)
93+
ar rcs $(prism_static_lib) $(prism_objects)
94+
95+
prism_lib: prism $(prism_static_lib)
96+
9197
src/%.o: src/%.c templates
9298
$(cc) -c $(flags) -fPIC $< -o $@
9399

100+
$(prism_src)/%.o: $(prism_src)/%.c prism
101+
$(cc) -c $(flags) -fPIC $(prism_flags) $< -o $@
102+
103+
$(prism_src)/util/%.o: $(prism_src)/util/%.c prism
104+
$(cc) -c $(flags) -fPIC $(prism_flags) $< -o $@
105+
94106
test/%.o: test/%.c templates
95107
$(cc) -c $(test_cflags) $(test_flags) $(prism_flags) $< -o $@
96108

97-
test: $(test_objects) $(non_main_objects)
98-
$(cc) $(test_objects) $(non_main_objects) $(test_cflags) $(test_ldflags) -o $(test_exec)
109+
test: $(test_objects) $(non_main_objects) $(prism_objects)
110+
$(cc) $(test_objects) $(non_main_objects) $(prism_objects) $(test_cflags) $(test_ldflags) -o $(test_exec)
99111

100112
clean:
101-
rm -f $(exec) $(test_exec) $(lib_name) $(shared_lib_name) $(ruby_extension)
102-
rm -rf $(objects) $(test_objects) $(extension_objects) lib/herb/*.bundle tmp
103-
rm -rf $(prism_path)
104-
rake prism:clean
113+
rm -f $(exec) $(test_exec) $(lib_name) $(shared_lib_name) $(prism_static_lib) $(ruby_extension)
114+
rm -rf $(objects) $(test_objects) $(prism_objects) $(extension_objects) lib/herb/*.bundle tmp
115+
bundle exec rake prism:clean
105116

106117
bundle_install:
107118
bundle install
@@ -110,8 +121,7 @@ templates: bundle_install
110121
bundle exec rake templates
111122

112123
prism: bundle_install
113-
cd $(prism_path) && ruby templates/template.rb && make static && cd -
114-
rake prism:vendor
124+
bundle exec rake prism:vendor
115125

116126
format:
117127
$(clang_format) -i $(project_and_extension_files)

Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ namespace :prism do
144144
exit 1
145145
end
146146

147+
puts "Generating Prism templates..."
148+
Dir.chdir(prism_bundle_path) do
149+
system("ruby templates/template.rb", exception: true)
150+
end
151+
147152
FileUtils.mkdir_p(prism_vendor_path)
148153

149154
files = [

java/Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ endif
2424

2525
BUILD_DIR = ../build
2626
SRC_DIR = ../src
27-
PRISM_PATH = $(shell cd .. && bundle show prism)
28-
PRISM_INCLUDE = $(PRISM_PATH)/include
29-
PRISM_BUILD = $(PRISM_PATH)/build
27+
PRISM_VENDOR_PATH = ../vendor/prism
28+
PRISM_INCLUDE = $(PRISM_VENDOR_PATH)/include
29+
PRISM_LIB = $(BUILD_DIR)/libprism.a
3030

3131
JAVAC = $(JAVA_HOME)/bin/javac
3232
JAVA_CMD = $(JAVA_HOME)/bin/java
3333
CFLAGS = -std=c99 -Wall -Wextra -fPIC -O2
34-
INCLUDES = -I. -I$(SRC_DIR)/include -I$(PRISM_INCLUDE) $(JNI_INCLUDES)
34+
INCLUDES = -I. -I$(SRC_DIR)/include -I$(PRISM_INCLUDE) -I$(PRISM_VENDOR_PATH)/src $(JNI_INCLUDES)
3535
LDFLAGS = -shared
36-
LIBS = $(PRISM_BUILD)/libprism.a
36+
LIBS = $(PRISM_LIB)
3737

3838
HERB_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/**/*.c)
3939
HERB_OBJECTS = $(filter-out $(SRC_DIR)/main.o, $(HERB_SOURCES:.c=.o))
@@ -48,13 +48,16 @@ JNI_LIB = $(BUILD_DIR)/$(JNI_LIB_PREFIX)herb_jni.$(JNI_LIB_EXT)
4848
JAVA_SOURCES = $(shell find org -name "*.java" 2>/dev/null)
4949
JAVA_TIMESTAMP = target/.java_compiled
5050

51-
.PHONY: all clean java jni test
51+
.PHONY: all clean java jni test prism_lib templates
5252

53-
all: templates jni java
53+
all: templates prism_lib jni java
5454

5555
templates:
5656
cd .. && bundle exec rake templates
5757

58+
prism_lib:
59+
cd .. && make prism_lib
60+
5861
jni: $(JNI_LIB)
5962

6063
$(JNI_LIB): $(JNI_OBJECTS) $(HERB_OBJECTS)
@@ -89,8 +92,9 @@ help:
8992
@echo "Herb Java/JNI Build System"
9093
@echo ""
9194
@echo "Targets:"
92-
@echo " all - Build everything (templates + JNI + Java)"
95+
@echo " all - Build everything (templates + prism_lib + JNI + Java)"
9396
@echo " templates - Generate code from ERB templates"
97+
@echo " prism_lib - Build prism static library"
9498
@echo " jni - Build JNI shared library"
9599
@echo " java - Compile Java classes"
96100
@echo " cli - Show CLI usage"

rust/Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BIN_NAME = herb-rust
55
BIN_PATH = $(BUILD_DIR)/debug/$(BIN_NAME)
66
RELEASE_BIN_PATH = $(BUILD_DIR)/release/$(BIN_NAME)
77

8-
.PHONY: all build release clean test cli help templates format vendor
8+
.PHONY: all build release clean test cli help templates format vendor prism_lib
99

1010
all: templates build
1111

@@ -44,16 +44,18 @@ clean:
4444
cargo clean
4545
@echo "Cleaned Rust build artifacts"
4646

47-
vendor:
47+
prism_lib:
48+
cd .. && make prism_lib
49+
50+
vendor: prism_lib
4851
@echo "Vendoring C sources into vendor/libherb..."
4952
rm -rf vendor/
5053
mkdir -p vendor/libherb/
5154
mkdir -p vendor/prism/
5255
cp -r ../src vendor/libherb/
5356
@echo "Vendoring prism library..."
54-
PRISM_PATH=$$(bundle show prism) && \
55-
cp -r "$$PRISM_PATH/src" vendor/prism/ && \
56-
cp -r "$$PRISM_PATH/include" vendor/prism/
57+
cp -r ../vendor/prism/src vendor/prism/
58+
cp -r ../vendor/prism/include vendor/prism/
5759
@echo "Vendored C sources and prism successfully"
5860

5961
help:
@@ -67,6 +69,7 @@ help:
6769
@echo " cli - Show CLI usage"
6870
@echo " test - Run Rust tests"
6971
@echo " format - Format Rust code with rustfmt"
72+
@echo " prism_lib - Build prism static library"
7073
@echo " vendor - Vendor C sources into vendor/"
7174
@echo " clean - Remove build artifacts"
7275
@echo " help - Show this help"

0 commit comments

Comments
 (0)