Skip to content

Commit

Permalink
Add basic libdl embedding test
Browse files Browse the repository at this point in the history
To check for regressions of
#57240
  • Loading branch information
topolarity committed Feb 3, 2025
1 parent 253bc4f commit 0ea3f84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/embedding/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EXE := $(suffix $(abspath $(JULIA)))

# get compiler and linker flags. (see: `contrib/julia-config.jl`)
JULIA_CONFIG := $(JULIA) -e 'include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "julia-config.jl"))' --
JULIA_LIBDIR := $(shell $(JULIA) -e 'println(joinpath(Sys.BINDIR, "..", "lib"))' --)
CPPFLAGS_ADD :=
CFLAGS_ADD = $(shell $(JULIA_CONFIG) --cflags)
LDFLAGS_ADD = -lm $(shell $(JULIA_CONFIG) --ldflags --ldlibs)
Expand All @@ -29,23 +30,30 @@ DEBUGFLAGS += -g

#=============================================================================

release: $(BIN)/embedding$(EXE)
debug: $(BIN)/embedding-debug$(EXE)
release: $(BIN)/embedding$(EXE) $(BIN)/libdl-embedding$(EXE)
debug: $(BIN)/embedding-debug$(EXE) $(BIN)/libdl-embedding$(EXE)

$(BIN)/embedding$(EXE): $(SRCDIR)/embedding.c
$(CC) $^ -o $@ $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS)

$(BIN)/embedding-debug$(EXE): $(SRCDIR)/embedding.c
$(CC) $^ -o $@ $(CPPFLAGS_ADD) $(CPPFLAGS) $(CFLAGS_ADD) $(CFLAGS) $(LDFLAGS_ADD) $(LDFLAGS) $(DEBUGFLAGS)

$(BIN)/libdl-embedding$(EXE): $(SRCDIR)/libdl_embedding.c
$(CC) $^ -o $@ $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -ldl -DLIBJULIA_PATH=\"$(JULIA_LIBDIR)/libjulia.so\"

$(BIN)/libdl-embedding-debug$(EXE): $(SRCDIR)/libdl_embedding.c
$(CC) $^ -o $@ $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(DEBUGFLAGS) -ldl -DLIBJULIA_PATH=\"$(JULIA_LIBDIR)/libjulia.so\"

ifneq ($(abspath $(BIN)),$(abspath $(SRCDIR)))
# for demonstration purposes, our demo code is also installed
# in $BIN, although this would likely not be typical
$(BIN)/LocalModule.jl: $(SRCDIR)/LocalModule.jl
cp $< $@
endif

check: $(BIN)/embedding$(EXE) $(BIN)/LocalModule.jl
check: $(BIN)/embedding$(EXE) $(BIN)/libdl-embedding$(EXE) $(BIN)/LocalModule.jl
$(BIN)/libdl-embedding$(EXE) # run w/o error
$(JULIA) --depwarn=error $(SRCDIR)/embedding-test.jl $<
@echo SUCCESS

Expand Down
12 changes: 12 additions & 0 deletions test/embedding/libdl_embedding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <dlfcn.h>
#include <stdio.h>
#include <signal.h>

int main(int argc, char *argv[])
{
// This test doesn't do much yet, except check
// https://github.com/JuliaLang/julia/issues/57240
signal(SIGCHLD, SIG_IGN);
void *handle = dlopen(LIBJULIA_PATH, RTLD_LAZY);
return 0;
}

0 comments on commit 0ea3f84

Please sign in to comment.