Skip to content

Commit

Permalink
Build and install libpython3.dll
Browse files Browse the repository at this point in the history
This provides the limited ABI as a separate DLL, forwarding to the
real one. This makes linking with "-lpython3" work.

Fixes #147
  • Loading branch information
lazka committed Apr 11, 2024
1 parent f7b84e1 commit c3ce130
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ LIBRARY_DEPS= @LIBRARY_DEPS@
LINK_PYTHON_DEPS=@LINK_PYTHON_DEPS@
PY_ENABLE_SHARED= @PY_ENABLE_SHARED@
STATIC_LIBPYTHON= @STATIC_LIBPYTHON@
ABI3DLLLIBRARY= libpython3.dll
ABI3LDLIBRARY= libpython3.dll.a


LIBS= @LIBS@
Expand Down Expand Up @@ -601,7 +603,7 @@ LIBEXPAT_HEADERS= \
# Default target
all: @DEF_MAKE_ALL_RULE@
build_all: check-clean-src $(BUILDPYTHON) $(BUILDPYTHONW) $(BUILDVENVLAUNCHER) $(BUILDVENVWLAUNCHER) platform oldsharedmods sharedmods \
gdbhooks Programs/_testembed python-config
gdbhooks Programs/_testembed python-config $(ABI3DLLLIBRARY) $(ABI3LDLIBRARY)
build_wasm: check-clean-src $(BUILDPYTHON) platform oldsharedmods python-config

# Check that the source is clean when building out of source.
Expand Down Expand Up @@ -728,6 +730,9 @@ pythonw_exe.o: $(srcdir)/PC/pythonw_exe.rc
python_nt.o: $(srcdir)/PC/python_nt.rc
$(WINDRES) $(RCFLAGS) -DORIGINAL_FILENAME=\\\"$(DLLLIBRARY)\\\" -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/python_nt.rc $@

python3dll_nt.o: $(srcdir)/PC/python_nt.rc
$(WINDRES) $(RCFLAGS) -DORIGINAL_FILENAME=\\\"$(ABI3DLLLIBRARY)\\\" -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/python_nt.rc $@

venvlauncher.o: $(srcdir)/PC/pylauncher.rc
$(WINDRES) $(RCFLAGS) -DPY_ICON -I$(srcdir)/Include -I$(srcdir)/PC -I. $(srcdir)/PC/pylauncher.rc $@

Expand Down Expand Up @@ -856,6 +861,10 @@ $(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS) python_nt.o
else true; \
fi

$(ABI3DLLLIBRARY) $(ABI3LDLIBRARY): python3dll_nt.o $(srcdir)/PC/launcher.c
$(LDSHARED) -DPYTHON_DLL_NAME=\"$(DLLLIBRARY)\" $(srcdir)/PC/python3dll.c -Wl,--out-implib=$(ABI3LDLIBRARY) -o $(ABI3DLLLIBRARY) python3dll_nt.o \
$(LDFLAGS_NODIST);

# wasm32-emscripten browser build
# wasm assets directory is relative to current build dir, e.g. "./usr/local".
# --preload-file turns a relative asset path into an absolute path.
Expand Down Expand Up @@ -1867,6 +1876,7 @@ altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
if test -n "$(DLLLIBRARY)" ; then \
$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
$(INSTALL_SHARED) $(ABI3DLLLIBRARY) $(DESTDIR)$(BINDIR); \
else \
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
if test $(LDLIBRARY) != $(INSTSONAME); then \
Expand Down Expand Up @@ -2301,6 +2311,7 @@ libainstall: all python-config
if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
if test "$(SHLIB_SUFFIX)" = .dll -o "$(SHLIB_SUFFIX)" = .pyd; then \
$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBDIR) ; \
$(INSTALL_DATA) $(ABI3LDLIBRARY) $(DESTDIR)$(LIBDIR) ; \
else \
$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
fi; \
Expand Down Expand Up @@ -2550,7 +2561,7 @@ clean: clean-retain-profile
fi

clobber: clean
-rm -f $(BUILDPYTHON) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
-rm -f $(BUILDPYTHON) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY)$(ABI3LDLIBRARY) $(ABI3DLLLIBRARY) \
tags TAGS \
config.cache config.log pyconfig.h Modules/config.c
-rm -rf build platform
Expand Down
8 changes: 8 additions & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3ce130

Please sign in to comment.