Skip to content

Commit c4448e2

Browse files
KristofferCclaude
andcommitted
Backport p7zip_jll infrastructure changes from f03e9c3
Bring over the p7zip_jll handling improvements from f03e9c3 ([deps] enable zstd support): - Move p7zip binary from bindir to private_libexecdir - Add Windows DLL handling for binary builder installs - Simplify p7zip_jll.jl by removing LIBPATH handling - Add P7ZIP_BUILD_OPTS variable for consistent build flags These changes prepare for the p7zip 17.7.0 upgrade and ensure p7zip is installed in the correct location. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 4a79cf9 commit c4448e2

File tree

3 files changed

+52
-65
lines changed

3 files changed

+52
-65
lines changed

Makefile

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ endif
204204

205205
# private libraries, that are installed in $(prefix)/lib/julia
206206
JL_PRIVATE_LIBS-0 := libccalltest libccalllazyfoo libccalllazybar libllvmcalltest
207+
JL_PRIVATE_LIBS-1 := # libraries from USE_SYSTEM=1
208+
JL_PRIVATE_EXES := 7z
209+
JL_PRIVATE_TOOLS := lld$(EXE) dsymutil$(EXE)
207210
ifeq ($(JULIA_BUILD_MODE),release)
208211
JL_PRIVATE_LIBS-0 += libjulia-internal libjulia-codegen
209212
else ifeq ($(JULIA_BUILD_MODE),debug)
@@ -325,9 +328,6 @@ endif
325328
-$(INSTALL_M) $(wildcard $(build_private_libdir)/*.a) $(DESTDIR)$(private_libdir)/
326329
-rm -f $(DESTDIR)$(private_libdir)/sys-o.a
327330

328-
# We have a single exception; we want 7z.dll to live in private_libexecdir,
329-
# not bindir, so that 7z.exe can find it.
330-
-mv $(DESTDIR)$(bindir)/7z.dll $(DESTDIR)$(private_libexecdir)/
331331
-$(INSTALL_M) $(build_bindir)/libopenlibm.dll.a $(DESTDIR)$(libdir)/
332332
-$(INSTALL_M) $(build_libdir)/libssp.dll.a $(DESTDIR)$(libdir)/
333333
else
@@ -384,14 +384,12 @@ endif
384384
done \
385385
done
386386
endif
387-
# Install `7z` into private_libexecdir
388-
$(INSTALL_M) $(build_bindir)/7z$(EXE) $(DESTDIR)$(private_libexecdir)/
389-
390-
# Install `lld` into private_libexecdir
391-
$(INSTALL_M) $(build_depsbindir)/lld$(EXE) $(DESTDIR)$(private_libexecdir)/
392-
393-
# Install `dsymutil` into private_libexecdir/
394-
$(INSTALL_M) $(build_depsbindir)/dsymutil$(EXE) $(DESTDIR)$(private_libexecdir)/
387+
for exe in $(JL_PRIVATE_EXES) ; do \
388+
$(INSTALL_M) $(build_private_libexecdir)/$$exe $(DESTDIR)$(private_libexecdir) || exit 1; \
389+
done
390+
for exe in $(JL_PRIVATE_TOOLS) ; do \
391+
$(INSTALL_M) $(build_depsbindir)/$$exe $(DESTDIR)$(private_libexecdir) || exit 1; \
392+
done
395393

396394
# Copy public headers
397395
cp -R -L $(build_includedir)/julia/* $(DESTDIR)$(includedir)/julia

deps/p7zip.mk

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ include $(SRCDIR)/p7zip.version
33

44
ifneq ($(USE_BINARYBUILDER_P7ZIP),1)
55

6+
P7ZIP_BUILD_OPTS := bindir=$(build_private_libexecdir) CC="$(CC)" CXX="$(CXX)"
7+
68
$(SRCCACHE)/p7zip-$(P7ZIP_VER).tar.gz: | $(SRCCACHE)
79
$(JLDOWNLOAD) $@ https://github.com/p7zip-project/p7zip/archive/refs/tags/v$(P7ZIP_VER).tar.gz
810

@@ -17,21 +19,21 @@ checksum-p7zip: $(SRCCACHE)/p7zip-$(P7ZIP_VER).tar.gz
1719

1820
$(BUILDDIR)/p7zip-$(P7ZIP_VER)/build-configured: $(BUILDDIR)/p7zip-$(P7ZIP_VER)/source-extracted
1921
$(BUILDDIR)/p7zip-$(P7ZIP_VER)/build-compiled: $(BUILDDIR)/p7zip-$(P7ZIP_VER)/build-configured
20-
$(MAKE) -C $(dir $<) $(MAKE_COMMON) CC="$(CC)" CXX="$(CXX)" 7za
22+
$(MAKE) -C $(dir $<) $(MAKE_COMMON) $(P7ZIP_BUILD_OPTS) 7za$(EXE)
2123
echo 1 > $@
2224

2325
define P7ZIP_INSTALL
24-
mkdir -p $2/$$(build_bindir)
25-
cp -a $1/bin/7za $2/$$(build_bindir)/7z
26+
mkdir -p $2/$$(build_private_libexecdir)/
27+
cp -a $1/bin/7za$(EXE) $2/$$(build_private_libexecdir)/7z$(EXE)
2628
endef
2729
$(eval $(call staged-install, \
2830
p7zip,p7zip-$(P7ZIP_VER), \
2931
P7ZIP_INSTALL,,,))
3032

3133
clean-p7zip:
3234
-rm -f $(BUILDDIR)/p7zip-$(P7ZIP_VER)/build-configured $(BUILDDIR)/p7zip-$(P7ZIP_VER)/build-compiled
33-
-rm -f $(build_bindir)/7za
34-
-$(MAKE) -C $(BUILDDIR)/p7zip-$(P7ZIP_VER) clean
35+
-rm -f $(build_bindir)/7z$(EXE) $(build_bindir)/7z$(EXE) $(build_private_libexecdir)/7z$(EXE)
36+
-$(MAKE) -C $(BUILDDIR)/p7zip-$(P7ZIP_VER) $(MAKE_COMMON) $(P7ZIP_BUILD_OPTS) clean
3537

3638
distclean-p7zip:
3739
rm -rf $(SRCCACHE)/p7zip-$(P7ZIP_VER).tar.gz $(SRCCACHE)/p7zip-$(P7ZIP_VER) $(BUILDDIR)/p7zip-$(P7ZIP_VER)
@@ -48,5 +50,23 @@ check-p7zip: compile-p7zip
4850
else # USE_BINARYBUILDER_P7ZIP
4951

5052
$(eval $(call bb-install,p7zip,P7ZIP,false))
53+
# move from bindir to shlibdir, where we expect to install it
54+
install-p7zip: post-install-p7zip
55+
uninstall-p7zip: pre-uninstall-p7zip
56+
post-install-p7zip: $(build_prefix)/manifest/p7zip
57+
mkdir -p $(build_private_libexecdir)/
58+
[ ! -e $(build_bindir)/7z$(EXE) ] || mv $(build_bindir)/7z$(EXE) $(build_private_libexecdir)/7z$(EXE)
59+
[ -e $(build_private_libexecdir)/7z$(EXE) ]
60+
ifeq ($(OS),WINNT)
61+
[ ! -e $(build_bindir)/7z.dll ] || mv $(build_bindir)/7z.dll $(build_private_libexecdir)/7z.dll
62+
[ -e $(build_private_libexecdir)/7z.dll ]
63+
endif
64+
pre-uninstall-p7zip:
65+
-rm -f $(build_private_libexecdir)/7z$(EXE)
66+
ifeq ($(OS),WINNT)
67+
-rm -f $(build_private_libexecdir)/7z.dll
68+
endif
69+
70+
.PHONY: post-install-p7zip pre-uninstall-p7zip
5171

5272
endif

stdlib/p7zip_jll/src/p7zip_jll.jl

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
baremodule p7zip_jll
55
using Base
66

7-
const PATH_list = String[]
8-
const LIBPATH_list = String[]
9-
107
export p7zip
118

129
# These get calculated in __init__()
1310
const PATH = Ref("")
14-
const LIBPATH = Ref("")
1511
artifact_dir::String = ""
1612
p7zip_path::String = ""
1713
if Sys.iswindows()
@@ -21,71 +17,44 @@ else
2117
end
2218

2319
if Sys.iswindows()
24-
const LIBPATH_env = "PATH"
25-
const LIBPATH_default = ""
2620
const pathsep = ';'
2721
elseif Sys.isapple()
28-
const LIBPATH_env = "DYLD_FALLBACK_LIBRARY_PATH"
29-
const LIBPATH_default = "~/lib:/usr/local/lib:/lib:/usr/lib"
3022
const pathsep = ':'
3123
else
32-
const LIBPATH_env = "LD_LIBRARY_PATH"
33-
const LIBPATH_default = ""
3424
const pathsep = ':'
3525
end
3626

37-
function adjust_ENV!(env::Dict{keytype(Base.EnvDict),valtype(Base.EnvDict)}, PATH::String, LIBPATH::String, adjust_PATH::Bool, adjust_LIBPATH::Bool)
38-
if adjust_LIBPATH
39-
LIBPATH_base = get(env, LIBPATH_env, expanduser(LIBPATH_default))
40-
if !isempty(LIBPATH_base)
41-
env[LIBPATH_env] = string(LIBPATH, pathsep, LIBPATH_base)
42-
else
43-
env[LIBPATH_env] = LIBPATH
44-
end
45-
end
46-
if adjust_PATH && (LIBPATH_env != "PATH" || !adjust_LIBPATH)
47-
if adjust_PATH
48-
if !isempty(get(env, "PATH", ""))
49-
env["PATH"] = string(PATH, pathsep, env["PATH"])
50-
else
51-
env["PATH"] = PATH
52-
end
53-
end
54-
end
55-
return env
27+
function adjust_ENV()
28+
addPATH = PATH[]
29+
oldPATH = get(ENV, "PATH", "")
30+
newPATH = isempty(oldPATH) ? addPATH : "$addPATH$pathsep$oldPATH"
31+
return ("PATH"=>newPATH,)
5632
end
5733

58-
function p7zip(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
59-
env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH)
60-
withenv(env...) do
61-
return f(p7zip_path)
34+
function p7zip(f::Function; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) # deprecated, for compat only
35+
withenv((adjust_PATH ? adjust_ENV() : ())...) do
36+
return f(p7zip())
6237
end
6338
end
64-
function p7zip(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
65-
env = adjust_ENV!(copy(ENV), PATH[], LIBPATH[], adjust_PATH, adjust_LIBPATH)
66-
return Cmd(Cmd([p7zip_path]); env)
67-
end
39+
# the 7z.exe we ship has no dependencies, so it needs no PATH adjustment
40+
p7zip(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true) = `$p7zip_path`
6841

6942
function init_p7zip_path()
7043
# Prefer our own bundled p7zip, but if we don't have one, pick it up off of the PATH
71-
# If this is an in-tree build, `7z` will live in `bindir`. Otherwise, it'll be in `private_libexecdir`
72-
for bundled_p7zip_path in (joinpath(Sys.BINDIR, Base.PRIVATE_LIBEXECDIR, p7zip_exe),
73-
joinpath(Sys.BINDIR, p7zip_exe))
74-
if isfile(bundled_p7zip_path)
75-
global p7zip_path = abspath(bundled_p7zip_path)
76-
return
77-
end
44+
# Our `7z` lives in `private_libexecdir`
45+
bundled_p7zip_path = joinpath(Sys.BINDIR, Base.PRIVATE_LIBEXECDIR, p7zip_exe)
46+
if isfile(bundled_p7zip_path)
47+
global p7zip_path = abspath(bundled_p7zip_path)
48+
else
49+
global p7zip_path = something(Sys.which(p7zip_exe), p7zip_exe)
7850
end
79-
global p7zip_path = something(Sys.which(p7zip_exe), p7zip_exe)
8051
end
8152

8253
function __init__()
8354
global artifact_dir = dirname(Sys.BINDIR)
8455
init_p7zip_path()
85-
PATH[] = dirname(p7zip_path)
86-
push!(PATH_list, PATH[])
87-
append!(LIBPATH_list, [joinpath(Sys.BINDIR, Base.LIBDIR, "julia"), joinpath(Sys.BINDIR, Base.LIBDIR)])
88-
LIBPATH[] = join(LIBPATH_list, pathsep)
56+
PATH[] = path = dirname(p7zip_path)
57+
nothing
8958
end
9059

9160
# JLLWrappers API compatibility shims. Note that not all of these will really make sense.

0 commit comments

Comments
 (0)