Files
SomberNight 31ed05c05c build: win: change from win-iconv to GNU libiconv
- (zbar requires [0] iconv)
- issues [1][3] compiling win-iconv:
    - pre-existing issue: lots of "-Wincompatible-pointer-types" warnings when compiling zbar with win-iconv
    - new debian means newer GCC
    - new GCC changed that [2] warning type to "error"
- GNU libiconv works as an alternative
    - drawback: win-iconv is more minimal, it uses the win32 API to do most of the work
    - still, is a 25+ year old GNU project with one release every ~2 years, so IMO fine

[0]: https://github.com/mchehab/zbar/blob/a549566ea11eb03622bd4458a1728ffe3f589163/README-windows.md
[1]: https://github.com/SomberNight/electrum/commit/cb00cb60cf9a0cb059dcac5e7acfe5186620cabe
[2]: https://gcc.gnu.org/pipermail/gcc-cvs/2023-December/394351.html

[3]: see snippet when compiling libzbar:
```
decoder.c: In function ‘zbar_decoder_reset’:
decoder.c:116:22: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  116 |     memset(dcode, 0, (long)&dcode->buf_alloc - (long)dcode);
      |                      ^
decoder.c:116:48: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  116 |     memset(dcode, 0, (long)&dcode->buf_alloc - (long)dcode);
      |                                                ^
  CC       processor/libzbar_la-win.lo
/bin/bash ../libtool --tag=RC   \
--mode=compile x86_64-w64-mingw32-windres -DHAVE_CONFIG_H -I. -I../include  \
-I../include  -o libzbar-rc.lo libzbar.rc
  CC       processor/libzbar_la-lock.lo
  CC       decoder/libzbar_la-qr_finder.lo
  CC       qrcode/libzbar_la-qrdec.lo
In file included from ./processor.h:26,
                 from processor/lock.c:25:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
  423 | #define _WIN32_WINNT 0x0500
      |         ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
                 from /usr/share/mingw-w64/include/crtdefs.h:10,
                 from /usr/share/mingw-w64/include/assert.h:15,
                 from processor/lock.c:24:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
  232 | #define _WIN32_WINNT 0xa00
      |         ^~~~~~~~~~~~
libtool: compile:  x86_64-w64-mingw32-windres -DHAVE_CONFIG_H -I. -I../include -I../include libzbar.rc  -o .libs/libzbar-rc.o
  CC       qrcode/libzbar_la-qrdectxt.lo
  CC       qrcode/libzbar_la-rs.lo
  CC       qrcode/libzbar_la-isaac.lo
  CC       qrcode/libzbar_la-bch15_5.lo
  CC       qrcode/libzbar_la-binarize.lo
  CC       qrcode/libzbar_la-util.lo
In file included from ./image.h:26,
                 from qrcode/binarize.c:10:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
  423 | #define _WIN32_WINNT 0x0500
      |         ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
                 from /usr/share/mingw-w64/include/crtdefs.h:10,
                 from /usr/share/mingw-w64/include/math.h:13,
                 from qrcode/binarize.c:7:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
  232 | #define _WIN32_WINNT 0xa00
      |         ^~~~~~~~~~~~
  CC       video/libzbar_la-dshow.lo
  CC       window/libzbar_la-win.lo
In file included from ./window.h:26,
                 from window/win.c:26:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
  423 | #define _WIN32_WINNT 0x0500
      |         ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
                 from /usr/share/mingw-w64/include/crtdefs.h:10,
                 from /usr/share/mingw-w64/include/ctype.h:9,
                 from window/win.c:24:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
  232 | #define _WIN32_WINNT 0xa00
      |         ^~~~~~~~~~~~
In file included from ./processor.h:26,
                 from processor/win.c:29:
../include/config.h:423:9: warning: "_WIN32_WINNT" redefined
  423 | #define _WIN32_WINNT 0x0500
      |         ^~~~~~~~~~~~
In file included from /usr/share/mingw-w64/include/corecrt.h:10,
                 from /usr/share/mingw-w64/include/crtdefs.h:10,
                 from /usr/share/mingw-w64/include/assert.h:15,
                 from processor/win.c:24:
/usr/share/mingw-w64/include/_mingw.h:232:9: note: this is the location of the previous definition
  232 | #define _WIN32_WINNT 0xa00
      |         ^~~~~~~~~~~~
processor/win.c: In function ‘_zbar_processor_open’:
processor/win.c:282:47: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  282 |     proc->display = CreateWindowEx(EXT_STYLE, (LPCTSTR)(long)wca, "ZBar",
      |                                               ^
processor/win.c: In function ‘_zbar_processor_close’:
processor/win.c:297:25: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  297 |         UnregisterClass((LPCTSTR)(long)proc->state->registeredClass, 0);
      |                         ^
  CC       window/libzbar_la-dib.lo
qrcode/qrdectxt.c: In function ‘qr_code_data_list_extract_text’:
qrcode/qrdectxt.c:302:62: error: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
  302 |                                               iconv(utf8_cd, &in, &inleft, &out,
      |                                                              ^~~
      |                                                              |
      |                                                              char **
In file included from qrcode/qrdectxt.c:12:
/usr/x86_64-w64-mingw32/include/iconv.h:43:56: note: expected ‘const char **’ but argument is of type ‘char **’
   43 |         size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
qrcode/qrdectxt.c:352:71: error: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
  352 |                                             err = iconv(enc_list[ei], &in,
      |                                                                       ^~~
      |                                                                       |
      |                                                                       char **
/usr/x86_64-w64-mingw32/include/iconv.h:43:56: note: expected ‘const char **’ but argument is of type ‘char **’
   43 |         size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
qrcode/qrdectxt.c:374:53: error: passing argument 2 of ‘iconv’ from incompatible pointer type [-Wincompatible-pointer-types]
  374 |                                       iconv(eci_cd, &in, &inleft, &out,
      |                                                     ^~~
      |                                                     |
      |                                                     char **
/usr/x86_64-w64-mingw32/include/iconv.h:43:56: note: expected ‘const char **’ but argument is of type ‘char **’
   43 |         size_t iconv(iconv_t cd, WINICONV_CONST char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
make[2]: *** [Makefile:1089: qrcode/libzbar_la-qrdectxt.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/opt/wine64/drive_c/electrum/contrib/zbar/zbar'
make[1]: *** [Makefile:1895: all-recursive] Error 1
make[1]: Leaving directory '/opt/wine64/drive_c/electrum/contrib/zbar'
make: *** [Makefile:989: all] Error 2
🗯 ERROR: Could not build zbar
🗯 ERROR: Could not build zbar

```
2026-02-28 07:41:45 +00:00

106 lines
3.9 KiB
Bash
Executable File

#!/bin/bash
set -e
here="$(dirname "$(readlink -e "$0")")"
test -n "$here" -a -d "$here" || exit
if [ -z "$WIN_ARCH" ] ; then
export WIN_ARCH="win64" # default
fi
if [ "$WIN_ARCH" = "win32" ] ; then
export GCC_TRIPLET_HOST="i686-w64-mingw32"
elif [ "$WIN_ARCH" = "win64" ] ; then
export GCC_TRIPLET_HOST="x86_64-w64-mingw32"
else
echo "unexpected WIN_ARCH: $WIN_ARCH"
exit 1
fi
export BUILD_TYPE="wine"
export GCC_TRIPLET_BUILD="x86_64-pc-linux-gnu"
export GCC_STRIP_BINARIES="1"
export CONTRIB="$here/.."
export PROJECT_ROOT="$CONTRIB/.."
export CACHEDIR="$here/.cache/$WIN_ARCH/build"
export PIP_CACHE_DIR="$here/.cache/$WIN_ARCH/wine_pip_cache"
export WINE_PIP_CACHE_DIR="c:/electrum/contrib/build-wine/.cache/$WIN_ARCH/wine_pip_cache"
export DLL_TARGET_DIR="$CACHEDIR/dlls"
export WINEPREFIX="/opt/wine64"
export WINEDEBUG=-all
export WINE_PYHOME="c:/python3"
export WINE_PYTHON="wine $WINE_PYHOME/python.exe -B"
. "$CONTRIB"/build_tools_util.sh
git -C "$PROJECT_ROOT" rev-parse 2>/dev/null || fail "Building outside a git clone is not supported."
info "Clearing $here/build and $here/dist..."
rm "$here"/build/* -rf
rm "$here"/dist/* -rf
mkdir -p "$CACHEDIR" "$DLL_TARGET_DIR" "$PIP_CACHE_DIR"
if ls "$DLL_TARGET_DIR"/libsecp256k1-*.dll 1> /dev/null 2>&1; then
info "libsecp256k1 already built, skipping"
else
"$CONTRIB"/make_libsecp256k1.sh || fail "Could not build libsecp"
fi
if [ -f "$DLL_TARGET_DIR/libzbar-0.dll" ]; then
info "libzbar already built, skipping"
else
(
# iconv is needed for zbar. see https://github.com/mchehab/zbar/blob/a549566ea11eb03622bd4458a1728ffe3f589163/README-windows.md
# (previously were using win-iconv, but changed to GNU libiconv due to compilation errors with modern gcc)
LIBICONV_VER="1.18"
download_if_not_exist "$CACHEDIR/libiconv-${LIBICONV_VER}.tar.gz" "https://ftp.gnu.org/pub/gnu/libiconv/libiconv-${LIBICONV_VER}.tar.gz"
verify_hash "$CACHEDIR/libiconv-${LIBICONV_VER}.tar.gz" "3b08f5f4f9b4eb82f151a7040bfd6fe6c6fb922efe4b1659c66ea933276965e8"
tar xf "$CACHEDIR/libiconv-${LIBICONV_VER}.tar.gz" -C "$CACHEDIR"
# ref https://github.com/msys2/MINGW-packages/blob/7f68e9f2488737bbe03888ade094eaee8021d1c5/mingw-w64-libiconv/PKGBUILD
info "Building libiconv..."
cd "$CACHEDIR/libiconv-${LIBICONV_VER}"
# Patches taken from msys2/MINGW-packages
patch -p1 < "$here/patches/libiconv-fix-pointer-buf.patch"
./configure \
$AUTOCONF_FLAGS \
--prefix="/usr/${GCC_TRIPLET_HOST}" \
--disable-static \
--enable-shared \
--enable-extra-encodings \
--enable-relocatable \
--disable-rpath \
--enable-silent-rules \
--enable-nls
CC="${GCC_TRIPLET_HOST}-gcc" make "-j$CPU_COUNT" || fail "Could not build libiconv"
cp -fpv "libcharset/lib/.libs/libcharset-1.dll" "$DLL_TARGET_DIR/" || fail "Could not copy the libcharset binary to DLL_TARGET_DIR"
cp -fpv "lib/.libs/libiconv-2.dll" "$DLL_TARGET_DIR/" || fail "Could not copy the libiconv binary to DLL_TARGET_DIR"
# FIXME avoid using sudo
sudo make install || fail "Could not install libiconv"
# workaround to delete files owned by root, created by "make install":
make clean
)
"$CONTRIB"/make_zbar.sh || fail "Could not build zbar"
fi
if [ -f "$DLL_TARGET_DIR/libusb-1.0.dll" ]; then
info "libusb already built, skipping"
else
"$CONTRIB"/make_libusb.sh || fail "Could not build libusb"
fi
"$here/prepare-wine.sh" || fail "prepare-wine failed"
info "Resetting modification time in C:\Python..."
# (Because of some bugs in pyinstaller)
pushd /opt/wine64/drive_c/python*
find -exec touch -h -d '2000-11-11T11:11:11+00:00' {} +
popd
ls -l /opt/wine64/drive_c/python*
"$here/build-electrum-git.sh" || fail "build-electrum-git failed"
info "Done."