OpenSC icon indicating copy to clipboard operation
OpenSC copied to clipboard

build: add support for meson

Open H5117 opened this issue 1 year ago • 69 comments

Fixes #3110, https://github.com/OpenSC/OpenSC/issues/2577.

H5117 avatar Apr 26 '24 09:04 H5117

@frankmorgner @Jakuje The libraries libopensc.so and libsmm-local.so are versioned independently of the project's version:

# LT Version numbers, remember to change them just *before* a release.
#   (Code changed:                      REVISION++)
#   (Oldest interface changed/removed:  OLDEST++)
#   (Interfaces added:                  CURRENT++, REVISION=0)
OPENSC_LT_CURRENT="11"
OPENSC_LT_OLDEST="11"
OPENSC_LT_REVISION="2"
OPENSC_LT_AGE="$((${OPENSC_LT_CURRENT}-${OPENSC_LT_OLDEST}))"

Questions:

  1. Why? Should not we use a project's version for all produced libraries?
  2. Should we version the library libsmm-local.so? What API it represents?

H5117 avatar Apr 27 '24 20:04 H5117

The OpenSC API is considered as an internal API (even though we still try to version it). The libssm-local.so is API for openSC to handle Secure Messaging. I think, in theory, it can be used as plug-able API for third party implementation of the SM talking to specific cards in "more secure" manner (read closed source).

I think the reason to version them separately is the SM API is much more stable (there are only few functions) so I think the idea was not to break it with the changes in opensc API, but I do not know if there are any users of this now.

Regarding the OpenSC API, as I mentioned previously, we consider it internal, we do not ship pkgconfig files and do not advise anyone using it outside of opensc tools. Generally, any application that wants to use OpenSC should go through the PKCS#11 API, which is standardized.

Jakuje avatar Apr 28 '24 10:04 Jakuje

@H5117 see https://www.sourceware.org/autobook/autobook/autobook_61.html for more information about the reasoning behind this library version.

frankmorgner avatar Apr 29 '24 12:04 frankmorgner

unittests, p11tests (code coverage, valgrind, fuzzing even though a switch exists, cmocka)

The test scripts in ./src/tests and ./tests hardcode paths to compiled tools and libraries, and these paths are different for autotools and meson. What should I do with it?

H5117 avatar Apr 30 '24 13:04 H5117

unittests, p11tests (code coverage, valgrind, fuzzing even though a switch exists, cmocka)

The test scripts in ./src/tests and ./tests hardcode paths to compiled tools and libraries, and these paths are different for autotools and meson. What should I do with it?

The paths are defined as part of AM_TESTS_ENVIRONMENT here:

https://github.com/OpenSC/OpenSC/blob/1fb5655d6907d380e9069fefb5e2ec9eaf8657eb/tests/Makefile.am#L11

So just creating an environment variable BUILD_PATH with the location of build directory from meson should make it transparent.

Jakuje avatar Apr 30 '24 13:04 Jakuje

clang-tidy

Meson automatically generates a target to check all sources in the project with clang-tidy (link). Is it OK for you or you need to check only specific files?

EDIT: implemented.

H5117 avatar Apr 30 '24 18:04 H5117

disable warning -Wno-unknown-warning-option if needed

Could you explain why you use this option only for some tools and not for the whole project?

H5117 avatar May 01 '24 12:05 H5117

By the way, should we install legacy symlinks for onepin-opensc-pkcs11.so in new build system? If someone decide to switch building to Meson, he can also switch to opensc-pkcs11.so.

H5117 avatar May 01 '24 19:05 H5117

disable warning -Wno-unknown-warning-option if needed

Could you explain why you use this option only for some tools and not for the whole project?

For some tools we are using code generation for CLI parsing. The generated files are causing this warning, so we need to disable this warning explicitly for those files.

frankmorgner avatar May 01 '24 22:05 frankmorgner

https://github.com/OpenSC/OpenSC/blob/1fb5655d6907d380e9069fefb5e2ec9eaf8657eb/src/tools/Makefile.am#L144-L148

frankmorgner avatar May 01 '24 22:05 frankmorgner

By the way, should we install legacy symlinks for onepin-opensc-pkcs11.so in new build system? If someone decide to switch building to Meson, he can also switch to opensc-pkcs11.so.

This is about PKCS#11 users rather than developers. We don't want to break existing configurations or scripts using the old location of the module.

frankmorgner avatar May 01 '24 22:05 frankmorgner

disable warning -Wno-unknown-warning-option if needed

Fixed.

H5117 avatar May 03 '24 08:05 H5117

thank you.

One thing we struggled setting up with the autotools is the pure static linking of the pkcs11 module. We had several tries of doing this, but did not manage to set this up correctly. opensc-pkcs11.so currently links dynamically aggainst libopensc and all external dependencies (e.g. zlib or openssl). Would it be possible to use static linking for all (internal/external) dependencies via meson?

frankmorgner avatar May 03 '24 09:05 frankmorgner

I added options to control static linking. Works for me.

Static linking
$ meson setup --wipe .. .
The Meson build system
Version: 1.4.0
Source dir: /home/user/OpenSC
Build dir: /home/user/OpenSC/build
Build type: native build
Project name: opensc
Project version: 0.25.1
C compiler for the host machine: cc (gcc 13.2.1 "cc (GCC) 13.2.1 20240417")
C linker for the host machine: cc ld.bfd 2.42.0
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: YES (/usr/bin/pkg-config) 2.1.1
Run-time dependency libpcsclite found: YES 2.1.0
Has header "winscard.h" with dependency libpcsclite: YES 
Has header "pcsclite.h" with dependency libpcsclite: YES 
Found CMake: /usr/bin/cmake (3.29.2)
Run-time dependency libeac found: NO (tried pkgconfig and cmake)
Run-time dependency openssl found: YES 3.3.0
Run-time dependency readline found: YES 8.2
Run-time dependency zlib found: YES 1.3.1
Run-time dependency appleframeworks found: NO (tried framework)
Run-time dependency threads found: YES
Run-time dependency gio-2.0 found: YES 2.80.0
Run-time dependency dl found: YES
Dependency p11-kit-1 skipped: feature p11kit disabled
Has header "inttypes.h" : YES 
Has header "string.h" : YES 
Has header "strings.h" : YES 
Has header "sys/time.h" : YES 
Has header "sys/mman.h" : YES 
Has header "sys/endian.h" : NO 
Has header "unistd.h" : YES 
Has header "endian.h" : YES 
Checking for function "getpass" : YES 
Checking for function "gettimeofday" : YES 
Checking for function "getline" : YES 
Checking for function "memset_s" : NO 
Checking for function "explicit_bzero" : YES 
Checking for function "strnlen" : YES 
Checking for function "sigaction" : YES 
Checking for function "__builtin_uadd_overflow" : YES 
Program git found: YES (/usr/bin/git)
Program gengetopt found: YES (/usr/bin/gengetopt)
Run-time dependency cmocka found: YES 1.1.7
Configuring config.h using configuration
Compiler for C supports arguments -Wno-unknown-warning-option: NO 
Configuring egk-tool.ggo using configuration
Configuring goid-tool.ggo using configuration
Configuring opensc-asn1.ggo using configuration
Configuring pkcs11-register.ggo using configuration
Configuring opensc-notify.ggo using configuration
Configuring org.opensc.notify.desktop using configuration
Configuring opensc.conf using configuration
Program xsltproc found: YES (/usr/bin/xsltproc)
Program clang-tidy found: YES (/usr/bin/clang-tidy)
Build targets in project: 98

opensc 0.25.1

  User defined options
    default_library     : shared
    prefix              : /usr
    bash_completion_path: /usr/share/bash-completion/completions
    components          : pkcs11,sm,tools
    libopensc           : static
    p11kit              : disabled
    tests               : true

Found ninja-1.12.0 at /usr/bin/ninja
$ ninja -j2
[198/374] Compiling C object src/tools/opensc-asn1.p/meson-generated_.._opensc-asn1-cmdline.c.o
src/tools/opensc-asn1-cmdline.c:228:1: warning: 'gengetopt_strdup' defined but not used [-Wunused-function]
  228 | gengetopt_strdup (const char *s)
      | ^~~~~~~~~~~~~~~~
[232/374] Compiling C object src/tests/check_macro_reference_loop.p/unittests_check_macro_reference_loop.c.o
In file included from ../src/tests/unittests/torture.h:24,
                 from ../src/tests/unittests/check_macro_reference_loop.c:24:
./config.h:128: warning: "SC_PKCS15_PROFILE_DIRECTORY" redefined
  128 | #define SC_PKCS15_PROFILE_DIRECTORY "/usr/share/opensc"
      | 
../src/tests/unittests/check_macro_reference_loop.c:22: note: this is the location of the previous definition
   22 | #define SC_PKCS15_PROFILE_DIRECTORY ""
      | 
[374/374] Generating doc/tools/westcos-tool with a custom command
$ meson install --destdir=/tmp/opensc
ninja: Entering directory `/home/user/OpenSC/build'
ninja: no work to do.
Installing src/pkcs11/libopensc-pkcs11.so to /tmp/opensc/usr/lib
Installing src/pkcs11/libpkcs11-spy.so to /tmp/opensc/usr/lib
Installing src/tools/cardos-tool to /tmp/opensc/usr/bin
Installing src/tools/dnie-tool to /tmp/opensc/usr/bin
Installing src/tools/dtrust-tool to /tmp/opensc/usr/bin
Installing src/tools/egk-tool to /tmp/opensc/usr/bin
Installing src/tools/eidenv to /tmp/opensc/usr/bin
Installing src/tools/goid-tool to /tmp/opensc/usr/bin
Installing src/tools/iasecc-tool to /tmp/opensc/usr/bin
Installing src/tools/openpgp-tool to /tmp/opensc/usr/bin
Installing src/tools/opensc-asn1 to /tmp/opensc/usr/bin
Installing src/tools/opensc-explorer to /tmp/opensc/usr/bin
Installing src/tools/opensc-tool to /tmp/opensc/usr/bin
Installing src/tools/pkcs11-register to /tmp/opensc/usr/bin
Installing src/tools/pkcs11-tool to /tmp/opensc/usr/bin
Installing src/tools/pkcs15-crypt to /tmp/opensc/usr/bin
Installing src/tools/pkcs15-tool to /tmp/opensc/usr/bin
Installing src/tools/cryptoflex-tool to /tmp/opensc/usr/bin
Installing src/tools/gids-tool to /tmp/opensc/usr/bin
Installing src/tools/netkey-tool to /tmp/opensc/usr/bin
Installing src/tools/piv-tool to /tmp/opensc/usr/bin
Installing src/tools/pkcs15-init to /tmp/opensc/usr/bin
Installing src/tools/sc-hsm-tool to /tmp/opensc/usr/bin
Installing src/tools/westcos-tool to /tmp/opensc/usr/bin
Installing src/tools/opensc-notify to /tmp/opensc/usr/bin
Installing src/smm/libsmm-local.so.11.0.2 to /tmp/opensc/usr/lib
Installing doc/tools/cardos-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/dnie-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/dtrust-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/egk-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/eidenv to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/goid-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/iasecc-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/openpgp-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/opensc-asn1 to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/opensc-explorer to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/opensc-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/pkcs11-register to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/pkcs11-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/pkcs15-crypt to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/pkcs15-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/cryptoflex-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/gids-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/netkey-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/piv-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/pkcs15-init to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/sc-hsm-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/westcos-tool to /tmp/opensc/usr/share/bash-completion/completions
Installing doc/tools/opensc-notify to /tmp/opensc/usr/share/bash-completion/completions
Installing /home/user/OpenSC/src/pkcs15init/asepcos.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/authentic.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/cardos.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/cyberflex.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/entersafe.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/epass2003.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/flex.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/gids.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/ias_adele_admin1.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/ias_adele_admin2.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/ias_adele_common.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/iasecc_admin_eid.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/iasecc_generic_oberthur.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/iasecc_generic_pki.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/iasecc.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/isoApplet.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/muscle.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/myeid.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/oberthur.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/openpgp.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/pkcs15.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/rutoken_ecp.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/rutoken_lite.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/rutoken.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/sc-hsm.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/setcos.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/src/pkcs15init/starcos.profile to /tmp/opensc/usr/share/opensc
Installing /home/user/OpenSC/build/meson-private/opensc-pkcs11.pc to /tmp/opensc/usr/lib/pkgconfig
Installing /home/user/OpenSC/build/src/tools/org.opensc.notify.desktop to /tmp/opensc/usr/share/applications
Installing /home/user/OpenSC/build/meson-private/opensc-smm.pc to /tmp/opensc/usr/lib/pkgconfig
Installing /home/user/OpenSC/etc/opensc.conf to /tmp/opensc/etc
Installing /home/user/OpenSC/build/etc/opensc.conf to /tmp/opensc/usr/share/doc/opensc
Installing /home/user/OpenSC/NEWS to /tmp/opensc/usr/share/doc/opensc
Installing symlink pointing to libsmm-local.so.11.0.2 to /tmp/opensc/usr/lib/libsmm-local.so.11
Installing symlink pointing to libsmm-local.so.11 to /tmp/opensc/usr/lib/libsmm-local.so
Installing symlink pointing to libopensc-pkcs11.so to /tmp/opensc/usr/lib/onepin-opensc-pkcs11.so
Installing symlink pointing to libopensc-pkcs11.so to /tmp/opensc/usr/lib/opensc-pkcs11.so
$ ldd /tmp/opensc/usr/lib/libopensc-pkcs11.so 
	linux-vdso.so.1 (0x00007ffd29592000)
	libcrypto.so.3 => /usr/lib/libcrypto.so.3 (0x00007f384e000000)
	libgio-2.0.so.0 => /usr/lib/libgio-2.0.so.0 (0x00007f384de33000)
	libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x00007f384ddd3000)
	libz.so.1 => /usr/lib/libz.so.1 (0x00007f384ddb9000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f384dbd7000)
	libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x00007f384da8a000)
	libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x00007f384da81000)
	libmount.so.1 => /usr/lib/libmount.so.1 (0x00007f384da31000)
	libffi.so.8 => /usr/lib/libffi.so.8 (0x00007f384da26000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x00007f384e7f1000)
	libpcre2-8.so.0 => /usr/lib/libpcre2-8.so.0 (0x00007f384d988000)
	libblkid.so.1 => /usr/lib/libblkid.so.1 (0x00007f384d94f000)
$ ldd /tmp/opensc/usr/lib/libsmm-local.so
	linux-vdso.so.1 (0x00007ffed87f2000)
	libcrypto.so.3 => /usr/lib/libcrypto.so.3 (0x00007e5297e00000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007e5297c1e000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x00007e529842b000)
$ ldd /tmp/opensc/usr/bin/pkcs11-tool 
	linux-vdso.so.1 (0x00007ffcf0deb000)
	libcrypto.so.3 => /usr/lib/libcrypto.so.3 (0x000075792ba00000)
	libz.so.1 => /usr/lib/libz.so.1 (0x000075792bed3000)
	libgio-2.0.so.0 => /usr/lib/libgio-2.0.so.0 (0x000075792b833000)
	libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x000075792b7d3000)
	libc.so.6 => /usr/lib/libc.so.6 (0x000075792b5f1000)
	libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x000075792b4a4000)
	libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x000075792b49d000)
	libmount.so.1 => /usr/lib/libmount.so.1 (0x000075792b44d000)
	libffi.so.8 => /usr/lib/libffi.so.8 (0x000075792b442000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x000075792c1e8000)
	libpcre2-8.so.0 => /usr/lib/libpcre2-8.so.0 (0x000075792b3a4000)
	libblkid.so.1 => /usr/lib/libblkid.so.1 (0x000075792b36b000)
$ 

For external dependencies Meson has an option prefer_static (link), which try to link to static dependencies if they exist. If static dependencies is a must, you can compile them as subprojects as part of building of OpenSC. To detect whether a static dependency is available, you can try dependency(..., static: true), but documentation says that it does not always work.

H5117 avatar May 03 '24 19:05 H5117

Thank you for this work so far. I think it is going in the right direction. I put there some inline comments. Can you also adjust the CI configuration and scripts to use the meson instead of autotools (at least for now to see how it behaves -- then we can figure out if we can adjust it somehow to run both).

Jakuje avatar May 03 '24 19:05 Jakuje

For external dependencies Meson has an option prefer_static (link), which try to link to static dependencies if they exist.

Yes, would be the preferred linking for pkcs11 modules (for both, internal and external dependencies). This would allow an application to include multiple pkcs11 modules with different types os versions of dependencies. For the opensc tools, however, shared linking woul be preferred for both.

frankmorgner avatar May 04 '24 08:05 frankmorgner

pure static linking of the pkcs11 module

I added optional compiling of static external dependencies, so this is now possible. With commands:

meson setup --prefix=/usr -Dcomponents=pkcs11 -Dp11kit=disabled -Dlibopensc=static --wrap-mode=forcefallback . build-static
cd build-static
meson configure -Dlibffi:default_library=static
meson configure -Dproxy-libintl:default_library=static

I get this result:

$ ldd src/pkcs11/libopensc-pkcs11.so
	linux-vdso.so.1 (0x00007ffcfafd6000)
	libmount.so.1 => /usr/lib/libmount.so.1 (0x0000760e6a5b0000)
	libc.so.6 => /usr/lib/libc.so.6 (0x0000760e6a3ce000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x0000760e6b21b000)
	libblkid.so.1 => /usr/lib/libblkid.so.1 (0x0000760e6a395000)
$

Currently OpenPACE and readline are not compiled, but can be added later.

H5117 avatar May 06 '24 08:05 H5117

pure static linking of the pkcs11 module

Implemented.

Commands:

$ meson setup . build-static/ -Dcomponents=pkcs11 -Dlibopensc=static --wrap-mode=forcefallback
$ cd build-static
$ meson configure -Dglib:libmount=disabled
$ meson configure -Dproxy-libintl:default_library=static
$ meson configure -Dlibffi:default_library=static

Result:

$ ldd src/pkcs11/opensc-pkcs11.so
	linux-vdso.so.1 (0x00007ffe39500000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007e3f4901e000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x00007e3f49f92000)

H5117 avatar May 14 '24 17:05 H5117

pure static linking of the pkcs11 module

Implemented.

Thank you, this was a long standing issue with autotools that meson now solves. I really think we should do this by default for the pkcs#11 module (e.g. without additional configuration parameters), but maybe there are different opinions.

I also really like that you already added a way of pulling and building the dependencies ("subprojects"). Is that done automatically when pkg-config cannot find it locally or does it need to be triggered during configuration? In any case, we should document the fact that we are pulling patches from mesonbuild.com in some cases.

From the CI side, it would still be nice to get a Github workflow that builds with meson. (Maybe I find some time at the end of the week for that.)

frankmorgner avatar May 15 '24 08:05 frankmorgner

I really think we should do this by default for the pkcs#11 module

I think we should not. GNU/Linux distributions always compile OpenSC tools, so statically compiled PKCS#11 library would be just a waste of memory. The right place for statically compiled PKCS#11 module in my opinion — a build artefact on the releases page of the project.

Is that done automatically when pkg-config cannot find it locally or does it need to be triggered during configuration?

Subprojects are compiled automatically, if they provide required dependencies (-Dopenpace=enabled is passed, for example) that are absent on the build machine. By default we declare external dependencies as optional (-Dopenpace=auto), so if a dependency is not found, the corresponding subproject won't be used (but can be forced manually).

From the CI side, it would still be nice to get a Github workflow that builds with meson.

My plan is to finish support for Windows first, to be sure that options or targets won't be changed.

H5117 avatar May 15 '24 12:05 H5117

I see that OpenSC.iss can't install/uninstall a minidriver, and you have not updated it since 2017. Is Inno Setup still supported?

H5117 avatar May 20 '24 07:05 H5117

Inno Setup still works and it is built in AppVeyor. However, we're only distributing the WiX installer for releases. I don't think ISS support is needed.

frankmorgner avatar May 21 '24 09:05 frankmorgner

Inno Setup still works and it is built in AppVeyor. However, we're only distributing the WiX installer for releases. I don't think ISS support is needed.

It is used also for the mingw builds in github actions. They create exe installers, but I think we do not publish them as part of release though. Not sure if this pipeline is needed then.

Jakuje avatar May 21 '24 09:05 Jakuje

How do you use or find gengetopt on Windows?

Just use a package from MSYS2.

Use this branch if you want to try building on Windows. It currently compiles all components except the minidriver. Also OpenPACE fails to build as a subproject (it does not honor DESTDIR on Windows for some reason).

H5117 avatar Jun 05 '24 16:06 H5117

Also, gengetopt needs to be configured with --include-getopt on Windows

Why don't you want to use your own version from src/common/compat_getopt.c?

By the way, what do you think about gnulib implementation?

H5117 avatar Jun 05 '24 16:06 H5117

Why don't you want to use your own version from src/common/compat_getopt.c?

Right, I forgot about that. I think meson (this PR's branch) doesn't notice that getopt is missing for including this file. I'll try meson.dev.

By the way, what do you think about gnulib implementation?

I don't have strong feelings, I just noticed the build failure on my machine.

frankmorgner avatar Jun 06 '24 06:06 frankmorgner

Just use a package from MSYS2.

Use this branch if you want to try building on Windows. It currently compiles all components except the minidriver. Also OpenPACE fails to build as a subproject (it does not honor DESTDIR on Windows for some reason).

I followed your recommendation and set it up with gengetopt from msys2 and your meson.dev branch.

However, I needed to modify some code regarding the missing getopt on Windows (getopt.diff)
diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index 1202420fb..3ddd691b6 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -143,8 +143,8 @@ endif
 .PHONY: cmdline
 cmdline:
 	@for f in *.ggo.in; do $(do_subst) < "$$f" > "$${f%.in}"; done
-	@for f in *.ggo;    do $(GENGETOPT) --file-name="$${f%.ggo}-cmdline" --output-dir=$(builddir) < "$$f"; done
-	$(AM_V_GEN)$(GENGETOPT) --file-name=opensc-asn1-cmdline --output-dir=$(builddir) --unamed-opts < opensc-asn1.ggo
+	@for f in *.ggo;    do $(GENGETOPT) --include-getopt --file-name="$${f%.ggo}-cmdline" --output-dir=$(builddir) < "$$f"; done
+	$(AM_V_GEN)$(GENGETOPT) --include-getopt --file-name=opensc-asn1-cmdline --output-dir=$(builddir) --unamed-opts < opensc-asn1.ggo
 
 if WIN32
 LIBS += -lshlwapi
diff --git a/src/tools/eidenv.c b/src/tools/eidenv.c
index 62ddd2164..8b607a8a0 100644
--- a/src/tools/eidenv.c
+++ b/src/tools/eidenv.c
@@ -29,7 +29,12 @@
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef HAVE_GETOPT
 #include <getopt.h>
+#else
+#include "common/compat_getopt.h"
+#endif
+
 #include "libopensc/opensc.h"
 #include "libopensc/asn1.h"
 #include "libopensc/cards.h"
diff --git a/src/tools/meson.build b/src/tools/meson.build
index a5cd5f92d..792837b22 100644
--- a/src/tools/meson.build
+++ b/src/tools/meson.build
@@ -88,6 +88,7 @@ executable('dtrust-tool',
 egk_tool_target = custom_target(
     command:[proggengetopt,
         '--input=@INPUT@',
+        '--include-getopt',
         '--set-version=' + meson.project_version(),
         '--output-dir=@OUTDIR@',
         '--file-name=egk-tool-cmdline'
@@ -134,6 +135,7 @@ executable('eidenv',
 goid_tool_target = custom_target(
     command:[proggengetopt,
         '--input=@INPUT@',
+        '--include-getopt',
         '--set-version=' + meson.project_version(),
         '--output-dir=@OUTDIR@',
         '--file-name=goid-tool-cmdline'
@@ -197,6 +199,7 @@ executable('openpgp-tool',
 opensc_asn1_target = custom_target(
     command:[proggengetopt,
         '--input=@INPUT@',
+        '--include-getopt',
         '--set-version=' + meson.project_version(),
         '--output-dir=@OUTDIR@',
         '--file-name=opensc-asn1-cmdline'
@@ -257,6 +260,7 @@ executable('opensc-tool',
 pkcs11_register_target = custom_target(
     command:[proggengetopt,
         '--input=@INPUT@',
+        '--include-getopt',
         '--set-version=' + meson.project_version(),
         '--output-dir=@OUTDIR@',
         '--file-name=pkcs11-register-cmdline'
@@ -447,6 +451,7 @@ if conf.get('ENABLE_OPENSSL')
         npa_tool_target = custom_target(
             command:[proggengetopt,
                 '--input=@INPUT@',
+                '--include-getopt',
                 '--set-version=' + meson.project_version(),
                 '--output-dir=@OUTDIR@',
                 '--file-name=npa-tool-cmdline'
@@ -487,6 +492,7 @@ if conf.get('ENABLE_NOTIFY')
     opensc_notify_targets += custom_target(
         command:[proggengetopt,
             '--input=@INPUT@',
+            '--include-getopt',
             '--set-version=' + meson.project_version(),
             '--output-dir=@OUTDIR@',
             '--file-name=opensc-notify-cmdline'
diff --git a/src/tools/openpgp-tool.c b/src/tools/openpgp-tool.c
index dfd72eab9..5ca004027 100644
--- a/src/tools/openpgp-tool.c
+++ b/src/tools/openpgp-tool.c
@@ -37,7 +37,11 @@
 #include <string.h>
 #include <ctype.h>
 
+#ifdef HAVE_GETOPT_H
 #include <getopt.h>
+#else
+#include "common/compat_getopt.h"
+#endif
 #include "libopensc/opensc.h"
 #include "libopensc/asn1.h"
 #include "libopensc/cards.h"
diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c
index 108e4f876..3c6ae8eb5 100644
--- a/src/tools/opensc-explorer.c
+++ b/src/tools/opensc-explorer.c
@@ -50,7 +50,11 @@
 #include "libopensc/internal.h"
 #include "libopensc/iso7816.h"
 #include "common/compat_strlcpy.h"
+#ifdef HAVE_GETOPT_H
 #include <getopt.h>
+#else
+#include "common/compat_getopt.h"
+#endif
 #include "util.h"
 
 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
diff --git a/src/tools/util.h b/src/tools/util.h
index 07c33f26b..7e62300c4 100644
--- a/src/tools/util.h
+++ b/src/tools/util.h
@@ -16,7 +16,11 @@
 #endif
 #include <sys/stat.h>
 
+#ifdef HAVE_GETOPT_H
 #include <getopt.h>
+#else
+#include "common/compat_getopt.h"
+#endif
 #include "libopensc/opensc.h"
 
 #ifdef __cplusplus

frankmorgner avatar Jun 12 '24 22:06 frankmorgner

Please show the error message. Also, meson.project_build_root() / 'getopt.h' exists?

H5117 avatar Jun 13 '24 07:06 H5117

This would be the first instance of the problem, that is solved with the patch above:

PS> meson compile -C builddir
Activating VS 17.7.4
INFO: automatically activated MSVC compiler environment
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: "C:\Program Files\Meson\ninja.EXE" -C C:/Users/Frank/OpenSC/OpenSC/builddir
ninja: Entering directory `C:/Users/Frank/OpenSC/OpenSC/builddir'
[110/231] Compiling C object src/libopensc/opensc-11.dll.p/log.c.obj
../src/libopensc/log.c(221): warning C4312: "Typumwandlung": Konvertierung von "int" in größeren Typ "HANDLE"
../src/libopensc/log.c(259): warning C4312: "Typumwandlung": Konvertierung von "int" in größeren Typ "HANDLE"
[153/231] Compiling C object src/tools/libutil.a.p/util.c.obj
FAILED: src/tools/libutil.a.p/util.c.obj
"cl" "-Isrc/tools\libutil.a.p" "-Isrc/tools" "-I..\src\tools" "-I." "-I.." "-Isrc" "-I..\src" "/MDd" "/nologo" "/showIncludes" "/utf-8" "/W2" "/Od" "/Zi" "-DHAVE_CONFIG_H" "/Fdsrc/tools\libutil.a.p\util.c.pdb" /Fosrc/tools/libutil.a.p/util.c.obj "/c" ../src/tools/util.c
C:\Users\Frank\OpenSC\OpenSC\src\tools\util.h(19): fatal error C1083: Datei (Include) kann nicht geöffnet werden: "getopt.h": No such file or directory
[162/231] Compiling C object src/libopensc/opensc-11.dll.p/reader-pcsc.c.obj
ninja: build stopped: subcommand failed.

frankmorgner avatar Jun 13 '24 08:06 frankmorgner

I suspect that you configured the project in MSYS2 environment, didn't you? If so, Meson correctly detects that /usr/include/getopt.h is present and doesn't copy your custom compat_getopt.h to the searchable path. Mixing environments is always a bad idea.

What I did is just adding C:\msys2\usr\bin to the PATH under MSVC environment. Could you try?

H5117 avatar Jun 13 '24 08:06 H5117