haskell-cryptography/HsOpenSSL

Unable to compile 0.11.7.3 on Windows and MacOS

Closed this issue · 9 comments

The commit where the build started failing is this one

commit c41e27deb0c48735efbae595311ac4fb820e6e8c (HEAD)
Author: Vladimir Shabanov <dev@vshabanov.com>
Date:   Sun Dec 11 20:32:54 2022 +0000

    Converted FFI imports from ccall to capi.

    Fixes #73. Part of #63.
$ uname -a
Darwin MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64

I have openssl@3 installed via Homebrew and PKG_CONFIG_PATH set like this:

export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
$ pkg-config --libs libssl
-L/opt/homebrew/Cellar/openssl@3/3.0.7/lib -lssl

The error I get when building is this:

cabal build all --enable-tests
Build profile: -w ghc-9.4.3 -O1
In order, the following will be built (use -v for more details):
 - HsOpenSSL-0.11.7.2 (lib:HsOpenSSL, test:test-der, test:test-dsa, test:test-evp-base64, test:test-evp-digest) (file OpenSSL.hs changed)
Preprocessing library for HsOpenSSL-0.11.7.2..
Building library for HsOpenSSL-0.11.7.2..
[27 of 33] Compiling OpenSSL.X509     ( /Users/jky/wrk/iohk/HsOpenSSL/dist-newstyle/build/aarch64-osx/ghc-9.4.3/HsOpenSSL-0.11.7.2/build/OpenSSL/X509.hs, /Users/jky/wrk/iohk/HsOpenSSL/dist-newstyle/build/aarch64-osx/ghc-9.4.3/HsOpenSSL-0.11.7.2/build/OpenSSL/X509.o, /Users/jky/wrk/iohk/HsOpenSSL/dist-newstyle/build/aarch64-osx/ghc-9.4.3/HsOpenSSL-0.11.7.2/build/OpenSSL/X509.dyn_o ) [Mismatched dynamic interface file]

/var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:25:100: error:
     error: implicit declaration of function 'X509_email_free' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
   |
25 | void ghczuwrapperZC4ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuemailzufree(void* a1) {X509_email_free(a1);}
   |                                                                                                    ^
void ghczuwrapperZC4ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuemailzufree(void* a1) {X509_email_free(a1);}
                                                                                                   ^

/var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:28:108: error:
     error: implicit declaration of function 'X509_get1_email' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
   |
28 | void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
   |                                                                                                            ^
void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
                                                                                                           ^

/var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:28:108: error:
     note: did you mean 'X509_get_ext'?
   |
28 | void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
   |                                                                                                            ^

/usr/local/include/openssl/x509.h:1096:17: error:
     note: 'X509_get_ext' declared here
     |
1096 | X509_EXTENSION *X509_get_ext(const X509 *x, int loc);
     |                 ^
X509_EXTENSION *X509_get_ext(const X509 *x, int loc);
                ^

/var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:28:108: error:
     warning: incompatible integer to pointer conversion returning 'int' from a function with result type 'void *' [-Wint-conversion]
   |
28 | void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
   |                                                                                                            ^
void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
                                                                                                           ^~~~~~~~~~~~~~~~~~~

In file included from /var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:45:0: error:


In file included from cbits/HsOpenSSL.h:20:0: error:

/usr/local/include/openssl/x509v3.h:1011:27: error:
     error: conflicting types for 'X509_get1_email'
     |
1011 | STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x);
     |                           ^
STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x);
                          ^

/var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:28:108: error:
     note: previous implicit declaration is here
   |
28 | void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
   |                                                                                                            ^
void* ghczuwrapperZC5ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuget1zuemail(X509* a1) {return X509_get1_email(a1);}
                                                                                                           ^

In file included from /var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:45:0: error:


In file included from cbits/HsOpenSSL.h:20:0: error:

/usr/local/include/openssl/x509v3.h:1013:6: error:
     error: conflicting types for 'X509_email_free'
     |
1013 | void X509_email_free(STACK_OF(OPENSSL_STRING) *sk);
     |      ^
void X509_email_free(STACK_OF(OPENSSL_STRING) *sk);
     ^

/var/folders/lm/7n3llnm96td8rxcdz1vx7j7w0000gn/T/ghc40796_0/ghc_22.c:25:100: error:
     note: previous implicit declaration is here
   |
25 | void ghczuwrapperZC4ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuemailzufree(void* a1) {X509_email_free(a1);}
   |                                                                                                    ^
void ghczuwrapperZC4ZCHsOpenSSLzm0zi11zi7zi2zminplaceZCOpenSSLziX509ZCX509zuemailzufree(void* a1) {X509_email_free(a1);}
                                                                                                   ^
1 warning and 4 errors generated.

<no location info>: error:
    `gcc' failed in phase `C Compiler'. (Exit code: 1)
glguy commented

The issue seems to be that we need to import x509v3.h and not x509.h in the various CApi FFI imports. replacing those import got things building again for me.

juhp commented

Seeing the same issue for Stackage Nightly for Linux

Same thing here on Linux with Cabal.

Sorry, can you check 2062a24 instead?

build-1.txt

build-2.txt

Builds for me, but with a lot of warnings.

Published 0.11.7.4 with these fixes, 0.11.7.3 is deprecated on Hackage.

There are a lot of warnings since there are a lot of deprecated functions in OpenSSL 3.0 (#63). Plus there are const/non-const pointer conversion warnings due to CApiFFI (perhaps it's possible to fix those).

Plus there are const/non-const pointer conversion warnings due to CApiFFI (perhaps it's possible to fix those).

Sadly, this is not possible right now, but it will be in GHC 9.6 via ConstPtr (see https://gitlab.haskell.org/ghc/ghc/-/issues/22043).