Skip to content

Commit

Permalink
combine libraries
Browse files Browse the repository at this point in the history
Signed-off-by: Ettore Di Giacinto <[email protected]>
  • Loading branch information
mudler committed Jan 12, 2025
1 parent 0a7732c commit f0a4425
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion backend/go/image/stablediffusion-ggml/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,34 @@ endif
# warnings
CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function

# Find all .a archives in ARCHIVE_DIR
# (ggml can have different backends cpu, cuda, etc., each backend generates a .a archive)
GGML_ARCHIVE_DIR := build/ggml/src/
ALL_ARCHIVES := $(shell find $(GGML_ARCHIVE_DIR) -type f -name '*.a')

# Name of the single merged library
COMBINED_LIB := libggmlall.a

# Rule to merge all the .a files into one
$(COMBINED_LIB): $(ALL_ARCHIVES)
@echo "Merging all .a into $(COMBINED_LIB)"
rm -f $@
mkdir -p merge-tmp
for a in $(ALL_ARCHIVES); do \
( cd merge-tmp && ar x ../$$a ); \
done
( cd merge-tmp && ar rcs ../$@ *.o )
# Ensure we have a proper index
ranlib $@
# Clean up
rm -rf merge-tmp

build/libstable-diffusion.a:
mkdir -p build && \
cd build && \
cmake $(CMAKE_ARGS) ../../../../../sources/stablediffusion-ggml.cpp && \
cmake --build . --config Release
$(MAKE) $(COMBINED_LIB)

gosd.o:
$(CXX) $(CXXFLAGS) gosd.cpp -o gosd.o -c
Expand All @@ -60,4 +83,4 @@ libsd.a: gosd.o
$(AR) rcs libsd.a gosd.o

clean:
rm -f gosd.o libsd.a build
rm -rf gosd.o libsd.a build $(COMBINED_LIB)
2 changes: 1 addition & 1 deletion backend/go/image/stablediffusion-ggml/gosd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

// #cgo CXXFLAGS: -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/thirdparty -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp -I${SRCDIR}/../../../../sources/stablediffusion-ggml.cpp/ggml/include
// #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
// #cgo LDFLAGS: -L${SRCDIR}/ -lsd -lstdc++ -lm -lggmlall -lgomp
// #include <gosd.h>
// #include <stdlib.h>
import "C"
Expand Down

0 comments on commit f0a4425

Please sign in to comment.