Openssl-sys on rust 32 bit msvc: Does it work?


#1

Hi!

I’m using the Rust 1.4 nightly MSVC on Windows from Monday and trying to use hyper in a project.

It fails with

   Compiling openssl-sys v0.6.5
     Running `E:\msgbox\target\debug\build\openssl-sys-e5961d79c8eedd0c\build-sc
ript-build`
       Fresh libressl-pnacl-sys v2.1.6
failed to run custom build command for `openssl-sys v0.6.5`
Process didn't exit successfully: `E:\msgbox\target\debug\build\openssl-sys-e596
1d79c8eedd0c\build-script-build` (exit code: 1112888148)
--- stdout
cargo:rustc-link-lib=dylib=eay32
cargo:rustc-link-lib=dylib=ssl32
TARGET = Some("i686-pc-windows-msvc")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("i686-pc-windows-msvc")
debug=true opt-level=0
TARGET = Some("i686-pc-windows-msvc")
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CC_i686-pc-windows-msvc = None
CC_i686_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CFLAGS_i686-pc-windows-msvc = None
CFLAGS_i686_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\cl.exe
" "/MD" "/Z7" "/nologo" "/Fo:E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961
d79c8eedd0c\\out\\src\\openssl_shim.o" "/c" "src/openssl_shim.c"
openssl_shim.c
src/openssl_shim.c(1) : fatal error C1083: Cannot open include file: 'openssl/hm
ac.h': No such file or directory


command did not execute successfully, got: exit code: 2



--- stderr
thread '<main>' panicked at 'explicit panic', C:\Users\kosta\.cargo\registry\src
\github.com-121aea75f9ef2ce2\gcc-0.3.14\src\lib.rs:667

Is this expected to work? Is there something I can do to fix?

Do the ming-w64 instructions from this thread apply to mscv, too?

Using mingw-w64 32bit: results in the same error from the mingw-w64 win32 shell

Using the pre-compiled openssl from http://slproweb.com/products/Win32OpenSSL.html results in

   Compiling openssl-sys v0.6.5
     Running `E:\msgbox\target\debug\build\openssl-sys-e5961d79c8eedd0c\build-sc
ript-build`
       Fresh libressl-pnacl-sys v2.1.6
failed to run custom build command for `openssl-sys v0.6.5`
Process didn't exit successfully: `E:\msgbox\target\debug\build\openssl-sys-e596
1d79c8eedd0c\build-script-build` (exit code: 1112888148)
--- stdout
cargo:rustc-link-search=native=C:\OpenSSL-Win32
cargo:rustc-link-lib=dylib=eay32
cargo:rustc-link-lib=dylib=ssl32
TARGET = Some("i686-pc-windows-msvc")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("i686-pc-windows-msvc")
debug=true opt-level=0
TARGET = Some("i686-pc-windows-msvc")
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CC_i686-pc-windows-msvc = None
CC_i686_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CFLAGS_i686-pc-windows-msvc = None
CFLAGS_i686_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\cl.exe
" "/MD" "/Z7" "/I" "C:\\OpenSSL-Win32\\include" "/nologo" "/Fo:E:\\msgbox\\targe
t\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\src\\openssl_shim.o" "/c" "s
rc/openssl_shim.c"
openssl_shim.c
TARGET = Some("i686-pc-windows-msvc")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("i686-pc-windows-msvc")
debug=true opt-level=0
TARGET = Some("i686-pc-windows-msvc")
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CC_i686-pc-windows-msvc = None
CC_i686_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CFLAGS_i686-pc-windows-msvc = None
CFLAGS_i686_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\cl.exe
" "/MD" "/Z7" "/I" "C:\\OpenSSL-Win32\\include" "/nologo" "/Fo:E:\\msgbox\\targe
t\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\ssl_ctx_options_shim.o" "/c"
 "E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\ssl_ctx_o
ptions_shim.c"
ssl_ctx_options_shim.c
TARGET = Some("i686-pc-windows-msvc")
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\lib.ex
e" "/OUT:E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\li
bopenssl_shim.a" "/nologo" "E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d
79c8eedd0c\\out\\src\\openssl_shim.o" "E:\\msgbox\\target\\debug\\build\\openssl
-sys-e5961d79c8eedd0c\\out\\ssl_ctx_options_shim.o"

--- stderr
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Error
{ repr: Os { code: 1, message: "Incorrect function." } }', ../src/libcore\result
.rs:734

So I guess that’s not compatible with msvc?

Any help is appreciated!

Thanks in advance!
Kosta

PS: For now, I can workaround this by using hyper = { version = '0.6.13', default-features = false } as dependency so I can build without https support - but I’d prefer to have https available. (Thanks, seanmonstar from #rust for that trick!)


#2

Hm, I never used MSVC to build hyper, but, as per above error, does your downloaded openssl distribution actually comes with header files (e.g. C:\OpenSSL-Win32\include\openssl\hmac.h is present)?

As for your build with mingw-w64 win32, for some reason your target triple ends in -msvc instead of -gnu as it should be. See explanation here, also see my answer here if you would like to use MSYS2.


#3

Thanks for your reply @semmaz and sorry for my delay in answering.

I’d like to compile with the Visual C++ compiler if possible.

Yeah I think in the last MSVC output I didn’t set OPENSSL_INCLUDE_DIR correctly. If I set that (and OPENSSL_LIB_DIR) I don’t get the hmac.h error anymore, but some really weird error:

E:\msgbox>cargo build
   Compiling openssl-sys v0.6.5
failed to run custom build command for `openssl-sys v0.6.5`
Process didn't exit successfully: `E:\msgbox\target\debug\build\openssl-sys-e596
1d79c8eedd0c\build-script-build` (exit code: 1112888148)
--- stdout
cargo:rustc-link-search=native=C:\OpenSSL-Win32\
cargo:rustc-link-lib=dylib=eay32
cargo:rustc-link-lib=dylib=ssl32
TARGET = Some("i686-pc-windows-msvc")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("i686-pc-windows-msvc")
debug=true opt-level=0
TARGET = Some("i686-pc-windows-msvc")
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CC_i686-pc-windows-msvc = None
CC_i686_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CFLAGS_i686-pc-windows-msvc = None
CFLAGS_i686_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC/bin\\cl.exe"
 "/MD" "/Z7" "/I" "C:\\OpenSSL-Win32\\include" "/nologo" "/Fo:E:\\msgbox\\target
\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\src\\openssl_shim.o" "/c" "sr
c/openssl_shim.c"
openssl_shim.c
TARGET = Some("i686-pc-windows-msvc")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("i686-pc-windows-msvc")
debug=true opt-level=0
TARGET = Some("i686-pc-windows-msvc")
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CC_i686-pc-windows-msvc = None
CC_i686_pc_windows_msvc = None
HOST_CC = None
CC = None
TARGET = Some("i686-pc-windows-msvc")
HOST = Some("i686-pc-windows-msvc")
CFLAGS_i686-pc-windows-msvc = None
CFLAGS_i686_pc_windows_msvc = None
HOST_CFLAGS = None
CFLAGS = None
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC/bin\\cl.exe"
 "/MD" "/Z7" "/I" "C:\\OpenSSL-Win32\\include" "/nologo" "/Fo:E:\\msgbox\\target
\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\ssl_ctx_options_shim.o" "/c"
"E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\ssl_ctx_op
tions_shim.c"
ssl_ctx_options_shim.c
TARGET = Some("i686-pc-windows-msvc")
running: "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC/bin\\lib.exe
" "/OUT:E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\lib
openssl_shim.a" "/nologo" "E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d7
9c8eedd0c\\out\\src\\openssl_shim.o" "E:\\msgbox\\target\\debug\\build\\openssl-
sys-e5961d79c8eedd0c\\out\\ssl_ctx_options_shim.o"

--- stderr
thread '<main>' panicked at 'called `Result::unwrap()` on an `Err` value: Error
{ repr: Os { code: 1, message: "Incorrect function." } }', ../src/libcore\result
.rs:736

No matter to which subdir I set the OPENSSL_LIB_DIR, I always get this error. Even if I rename e.g. libssl32.dll and libeay32.dll to remove the “lib” prefix.

I tried for OPENSSL_LIB_DIR:
C:\OpenSSL-Win32
C:\OpenSSL-Win32\bin
C:\OpenSSL-Win32\lib
C:\OpenSSL-Win32\lib\VC
C:\OpenSSL-Win32\lib\VC\static

(also in combination with OPENSSL_STATIC)

I tried to get smart from this build script, but it seems to error out in the config_file…compile(…) part.

It seems I either need to get stack traces to work, or figure out how to debug the GCC crate…

Any further help is appreciated. Thanks in advance!

Cheers,
Kosta


#4

I ran this on the command line and it gives

LINK : fatal error LNK1104: cannot open file 'E:\\msgbox\\target\\debug\\build\\
openssl-sys-e5961d79c8eedd0c\\out\\lib\\openssl_shim.a'

openssl_shim.a is in out\, not in out\lib\.

Running this manually with the correct path works:

"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC/bin\\lib.exe" "/OUT:E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\openssl_shim.a" "/nologo" "E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\src\\openssl_shim.o" "E:\\msgbox\\target\\debug\\build\\openssl-sys-e5961d79c8eedd0c\\out\\ssl_ctx_options_shim.o"

So I guess I’ll poke around in gcc to see where that link command goes wrong…

UPDATE: Ok it seems that this error was that I built something on a network share where hard-linking doesn’t work. Submitted this PR to fix in package gcc: https://github.com/alexcrichton/gcc-rs/pull/57

UPDATE Ok, I got it to work after copying my source to the local hard drive. I set OPENSSL_LIB_DIR to C:\OpenSSL-Win32\lib and had to rename some .lib files like libeay32.lib to eay32.lib. This compiled. To run it, I also had to copy DLLs libeay32.dll, libssl32.dll and ssleay32.dll to the Windows directory for my program to start. I might try later to link it statically, but for now this works.


#5

Ok my patch got applies and openssl-sys depends on gcc = “0.3” so a cargo update pulled that dependency.

E:\msgbox>cargo update
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating gcc v0.3.15 -> v0.3.16
    Updating hyper v0.6.13 -> v0.6.14

Now everything compiles thanks to the pre-compiled openssl. Thanks @alexcrichton for merging! :slight_smile:

I’ll update this topic if I get around to try linking OpenSSL statically.