Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: include manifests in .rc files #3173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

H5117
Copy link
Contributor

@H5117 H5117 commented Jun 6, 2024

This avoids using MSVC-specific mt.exe or link.exe and simplify building for MinGW and Cygwin.

@frankmorgner
Copy link
Member

I'm not familiar with the detailed process of how these pieces fit together on Windows. Do you have some internet ressource with background information on this?

In particular, I wonder what the digit in front of RT_MANIFEST means.

@H5117
Copy link
Contributor Author

H5117 commented Jun 6, 2024

I'm not familiar with the detailed process of how these pieces fit together on Windows. Do you have some internet ressource with background information on this?

Background information is here, but I am also don't clearly understand how it works. Particularly, I tried to generate manifests automatically with /MANIFEST:EMBED, but it did not work for me (resulting manifests did not contain any information about dependencies).

In particular, I wonder what the digit in front of RT_MANIFEST means.

Explanation is here.

@H5117 H5117 marked this pull request as draft June 6, 2024 16:38
@frankmorgner
Copy link
Member

This changeset looks reasonable then, thank you. Is there anything missing to complete this draft?

@frankmorgner
Copy link
Member

Oh, I see. There is a build failure using the nmake files:

lib /nologo /machine:x86 /out:pkcs15init.lib pkcs15-lib.obj profile.obj  pkcs15-cflex.obj  pkcs15-cardos.obj pkcs15-starcos.obj  pkcs15-oberthur.obj pkcs15-oberthur-awp.obj  pkcs15-setcos.obj  pkcs15-muscle.obj pkcs15-asepcos.obj pkcs15-rutoken.obj  pkcs15-entersafe.obj pkcs15-rtecp.obj  pkcs15-myeid.obj pkcs15-authentic.obj pkcs15-iasecc.obj  pkcs15-epass2003.obj pkcs15-openpgp.obj pkcs15-sc-hsm.obj  pkcs15-isoApplet.obj pkcs15-gids.obj
NMAKE : fatal error U1073: don't know how to make '..\..\win32\versioninfo.res'
Stop.
NMAKE : fatal error U1073: don't know how to make '..\..\src\libopensc\opensc_a.lib'
Stop.
NMAKE : fatal error U1073: don't know how to make '..\..\src\libopensc\opensc.lib'
Stop.
NMAKE : fatal error U1073: don't know how to make '..\..\src\libopensc\opensc_a.lib'
Stop.
NMAKE : fatal error U1073: don't know how to make '..\..\src\libopensc\opensc_a.lib'
Stop.
NMAKE : fatal error U1077: 'for' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'for' : return code '0x2'
Stop.

Copy link
Contributor Author

@H5117 H5117 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it would be nice to rename files accordingly.
versioninfo-pkcs11.rc.in -> opensc-pkcs11.rc.in
exe.manifest -> opensc-tools.manifest

@@ -37,7 +37,7 @@ BEGIN
END

#ifndef __MINGW32__
2 RT_MANIFEST "@abs_top_srcdir@\\src\\pkcs11\\opensc-pkcs11.dll.manifest"
2 RT_MANIFEST "..\\..\\src\\pkcs11\\opensc-pkcs11.dll.manifest"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to @abs_top_srcdir@ intentionally to support out-of-source builds (Meson does not support in-source builds by design). Why have you changed it back?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to hint this in the commit message. All previous CI runs failed, for example this one, because when we use nmake, we run ./configure in a cygwin environment, which replaces abs_top_srcdir with the cygpath. However, when we build the files with nmake, only actual windows paths must be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see. We have three options here:

  1. Use native Cygwin's windres to compile resources;
  2. Introduce a new substitution variable with a correct path (is it possible to do in configure.ac?). On Cygwin we should call cygpath to get the correct path;
  3. Close this PR and create separate .rc files with manifests for Meson only.

I personally vote for the third point, because it is relatively simple to implement (for me). What do you think?

@frankmorgner
Copy link
Member

Could you try the following?

diff --git a/configure.ac b/configure.ac
index b8224b5de..1bdbc9a01 100644
--- a/configure.ac
+++ b/configure.ac
@@ -980,6 +980,15 @@ if test "${enable_sm}" = "yes"; then
        esac
 fi
 
+case "${host}" in
+       *-winnt*|*-cygwin*)
+                       win_abs_top_srcdir="$(cygpath --windows $(realpath ${srcdir}))"
+                       ;;
+       *)
+                       win_abs_top_srcdir="$(realpath ${srcdir})"
+                       ;;
+esac
+
 if test "${with_pkcs11_provider}" = "detect"; then
        if test "${WIN32}" != "yes"; then
                DEFAULT_PKCS11_PROVIDER="${libdir}/opensc-pkcs11${DYN_LIB_EXT}"
@@ -1126,6 +1135,7 @@ AC_SUBST([PROFILE_DIR_DEFAULT])
 AC_SUBST([OPTIONAL_NOTIFY_CFLAGS])
 AC_SUBST([OPTIONAL_NOTIFY_LIBS])
 AC_SUBST([TIDY_CHECKS])
+AC_SUBST([win_abs_top_srcdir])
 
 AM_CONDITIONAL([ENABLE_MAN], [test "${enable_man}" = "yes"])
 AM_CONDITIONAL([ENABLE_THREAD_LOCKING], [test "${enable_thread_locking}" = "yes"])
diff --git a/src/minidriver/versioninfo-minidriver.rc.in b/src/minidriver/versioninfo-minidriver.rc.in
index 4844a14b0..fede775a8 100644
--- a/src/minidriver/versioninfo-minidriver.rc.in
+++ b/src/minidriver/versioninfo-minidriver.rc.in
@@ -5,9 +5,9 @@
 #define IDI_SMARTCARD       102
 
 #ifndef __MINGW32__
-IDI_SMARTCARD          ICON                    "..\\..\\win32\\DDORes.dll_14_2302.ico"
+IDI_SMARTCARD          ICON                    "@win_abs_top_srcdir@\\win32\\DDORes.dll_14_2302.ico"
 #else
-IDI_SMARTCARD          ICON                    "../../win32/DDORes.dll_14_2302.ico"
+IDI_SMARTCARD          ICON                    "@win_abs_top_srcdir@/win32/DDORes.dll_14_2302.ico"
 #endif
 
 VS_VERSION_INFO VERSIONINFO
diff --git a/src/tools/versioninfo-opensc-notify.rc.in b/src/tools/versioninfo-opensc-notify.rc.in
index 3b01d660b..7a895ec5e 100644
--- a/src/tools/versioninfo-opensc-notify.rc.in
+++ b/src/tools/versioninfo-opensc-notify.rc.in
@@ -5,9 +5,9 @@
 #define IDI_SMARTCARD       102
 
 #ifndef __MINGW32__
-IDI_SMARTCARD          ICON                    "..\\..\\win32\\DDORes.dll_14_2302.ico"
+IDI_SMARTCARD          ICON                    "@win_abs_top_srcdir@\\win32\\DDORes.dll_14_2302.ico"
 #else
-IDI_SMARTCARD          ICON                    "../../win32/DDORes.dll_14_2302.ico"
+IDI_SMARTCARD          ICON                    "@win_abs_top_srcdir@/win32/DDORes.dll_14_2302.ico"
 #endif
 
 VS_VERSION_INFO VERSIONINFO

@H5117 H5117 force-pushed the manifests branch 3 times, most recently from a1a7a48 to a69ab9e Compare June 10, 2024 13:01
@H5117
Copy link
Contributor Author

H5117 commented Jun 10, 2024

Could you explain the failure in MinGW? opensc-notify.rc is not compiled at all, but opensc-notify.c is compiled twice. Some conflict in rules?

@frankmorgner
Copy link
Member

Not really, but as in #3170 we should be able to avoid 3 of the 4 problems by declaring the call back functions static. WinMain needs to be non-static, however. I'm not sure if this is related to problems like this one or if we are doing something wrong in assembling the object files...

@H5117 H5117 marked this pull request as ready for review June 11, 2024 14:03
@H5117
Copy link
Contributor Author

H5117 commented Jun 11, 2024

It's definitely some conflict in rules. Autotools needs to generate opensc-notify.o, and instead of compiling it from opensc-notify.rc, it compiles opensc-notify.c because both rules exist.

I renamed the file to opensc-notify-x.rc. Should work now.

@frankmorgner
Copy link
Member

If that helps, OK, but then I think you can equally stick to the versioninfo- prefix that the rc files currently have.

@H5117
Copy link
Contributor Author

H5117 commented Jun 11, 2024

The prefix versioninfo is not correct even without this patch, because the .rc file contains the icon also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants