Skip to content

Commit f0a4425

Browse files
committed
combine libraries
Signed-off-by: Ettore Di Giacinto <[email protected]>
1 parent 0a7732c commit f0a4425

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

backend/go/image/stablediffusion-ggml/Makefile

+24-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,34 @@ endif
4646
# warnings
4747
CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
4848

49+
# Find all .a archives in ARCHIVE_DIR
50+
# (ggml can have different backends cpu, cuda, etc., each backend generates a .a archive)
51+
GGML_ARCHIVE_DIR := build/ggml/src/
52+
ALL_ARCHIVES := $(shell find $(GGML_ARCHIVE_DIR) -type f -name '*.a')
53+
54+
# Name of the single merged library
55+
COMBINED_LIB := libggmlall.a
56+
57+
# Rule to merge all the .a files into one
58+
$(COMBINED_LIB): $(ALL_ARCHIVES)
59+
@echo "Merging all .a into $(COMBINED_LIB)"
60+
rm -f $@
61+
mkdir -p merge-tmp
62+
for a in $(ALL_ARCHIVES); do \
63+
( cd merge-tmp && ar x ../$$a ); \
64+
done
65+
( cd merge-tmp && ar rcs ../$@ *.o )
66+
# Ensure we have a proper index
67+
ranlib $@
68+
# Clean up
69+
rm -rf merge-tmp
70+
4971
build/libstable-diffusion.a:
5072
mkdir -p build && \
5173
cd build && \
5274
cmake $(CMAKE_ARGS) ../../../../../sources/stablediffusion-ggml.cpp && \
5375
cmake --build . --config Release
76+
$(MAKE) $(COMBINED_LIB)
5477

5578
gosd.o:
5679
$(CXX) $(CXXFLAGS) gosd.cpp -o gosd.o -c
@@ -60,4 +83,4 @@ libsd.a: gosd.o
6083
$(AR) rcs libsd.a gosd.o
6184

6285
clean:
63-
rm -f gosd.o libsd.a build
86+
rm -rf gosd.o libsd.a build $(COMBINED_LIB)

backend/go/image/stablediffusion-ggml/gosd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package main
22

33
// #cgo CXXFLAGS: -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/thirdparty -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/ggml/include
4-
// #cgo LDFLAGS: -L${SRCDIR}/ -L${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/build/ggml/src/ggml-cpu -L${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/build/ggml/src -lsd -lstdc++ -lm -lggml -lggml-base -lggml-cpu -lgomp
4+
// #cgo LDFLAGS: -L${SRCDIR}/ -lsd -lstdc++ -lm -lggmlall -lgomp
55
// #include <gosd.h>
66
// #include <stdlib.h>
77
import "C"

0 commit comments

Comments
 (0)