Skip to content

Commit

Permalink
Fix install on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed May 28, 2024
1 parent da5b330 commit 5e1c3ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
build-wheels:
name: Build ${{ matrix.only }}
name: build ${{ matrix.only }}
needs: build-wheels-matrix
runs-on: ${{ matrix.os }}

Expand All @@ -93,7 +93,7 @@ jobs:
env:
CIBW_BUILD_VERBOSITY: 1
# add compiled libmagic to the build directory (to include in the wheel)
CIBW_BEFORE_BUILD: ${{ ( startsWith( matrix.os, 'macos' ) && 'sudo -E bash add_libmagic.sh' ) || 'bash add_libmagic.sh' }}
CIBW_BEFORE_BUILD: ${{ ( startsWith( matrix.os, 'macos' ) && 'sudo chmod -R 777 /usr/local && bash add_libmagic.sh' ) || 'bash add_libmagic.sh' }}
# build macos wheels with maximum backwards compatibility (gcc -mmacosx-version-min flag)
MACOSX_DEPLOYMENT_TARGET: ${{ ( endsWith( matrix.only, 'arm64' ) && '11.0' ) || '10.9' }}
# simple smoke test run on each wheel: this is an HLS MP4 video, only recognised in recent versions of libmagic
Expand Down
27 changes: 15 additions & 12 deletions add_libmagic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ install_source() {
# install from source
# https://www.darwinsys.com/file/
# https://github.com/file/file/blob/FILE5_45/INSTALL#L51
version="file-5.45" &&
tmpfile="$(mktemp)" &&
curl -sSLo "${tmpfile}" "https://astron.com/pub/file/${version}.tar.gz" &&
tar xvf "${tmpfile}" &&
cd "${version}" &&
./configure &&
make &&
make install &&
make installcheck &&
cd .. &&
rm -r "${version}"
(
version="file-5.45" &&
tmpfile="$(mktemp)" &&
curl -sSLo "${tmpfile}" "https://astron.com/pub/file/${version}.tar.gz" &&
tar xvf "${tmpfile}" &&
cd "${version}" &&
./configure &&
make &&
make install &&
make installcheck &&
cd .. &&
rm -r "${version}"
) || ( cd .. && false )
}

install_precompiled() {
Expand All @@ -37,6 +39,7 @@ install_precompiled() {
else
# windows (no install, just download into current working directory)
# could also consider install using `pacman`: https://packages.msys2.org/base/mingw-w64-file
# which would require an update of copy_libmagic below to account for new magic.mgc paths
python <<EOF
import platform, sysconfig, io, zipfile, urllib.request
assert platform.system() == "Windows"
Expand All @@ -56,7 +59,7 @@ copy_libmagic() {
# this python command relies on current working directory containing `./magic/loader.py`
libmagic_path="$(python -c 'from magic.loader import load_lib; print(load_lib()._name)')" &&
cp "${libmagic_path}" "magic" &&
# only on linux: additionally copy compiled db into magic dir (prefer the one installed by install_source)
# only on linux/macos: additionally copy compiled db into magic dir (prefer the one installed by install_source)
( ( cp "/usr/local/share/misc/magic.mgc" "magic" || cp "/usr/share/misc/magic.mgc" "magic" ) || true ) &&
# check what was copied
ls -ltra magic
Expand Down

0 comments on commit 5e1c3ca

Please sign in to comment.