Skip to content

Instantly share code, notes, and snippets.

View retep998's full-sized avatar
🐇
Very fluffy

Peter Atashian retep998

🐇
Very fluffy
  • Massachusetts, USA
View GitHub Profile
@retep998
retep998 / Guide.md
Last active December 26, 2020 03:50

Installing OpenSSL for Rust on Windows with MSVC

When using MSVC Rust on Windows, everything typically works out of the box, up until you decide to do some web stuff with hyper. Suddenly a new dependency, openssl, is failing to build and you have no idea how to fix it. Fortunately this guide is here to save you!

WARNING: OpenSSL 1.1 support was only added in openssl-sys = "0.9". Older versions only support up to OpenSSL 1.0.2. sfackler/rust-openssl#452

  1. First you will need to download and install OpenSSL itself. You can download an installer from http://slproweb.com/products/Win32OpenSSL.html. In particular you want the newest version and not the light version. Make sure it matches the version of Rust you have, if you're using x86_64-pc-windows-msvc you will want Win64, and if you're using i9686-pc-windows-msvc you will want Win32. For the purpose of example I have installed Win64 OpenSSL v1.0.2h.
  2. If all went well you should now have OpenSSL installed somewh
@retep998
retep998 / a.rs
Last active April 15, 2019 22:45
#![crate_type = "dylib"]
pub const FOO: &str = "FOO";
pub static BAR: &str = "BAR";
@retep998
retep998 / test.rs
Last active January 9, 2018 14:44
Linking Rust using LLVM and MSVC. No MinGW at all.
// Let's build rust programs with msvc linker!
// Started by klutzy
// Continued by Retep998
// Command line
/*
SET PATH=C:\WINDOWS;C:\WINDOWS\System32;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64;A:\rust64\bin;A:\LLVM\bin
rustc libcore\lib.rs --target=x86_64-pc-windows -Car=llvm-ar
rustc test.rs --emit=obj --target=x86_64-pc-windows --extern core=libcore.rlib
link "test.o" "libcore.rlib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "libcmt.lib" /LIBPATH:"C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\amd64"
[package]
name = "masstest"
version = "0.1.0"
authors = ["Peter"]
[profile.release]
lto = true
[dependencies]
advapi32-sys = "0.2.0"
#include <iostream>
using namespace std;
struct Bar {
~Bar() {
cout << "C++ destructor is firing" << endl;
}
};
extern "C" {
@retep998
retep998 / Cargo.toml
Last active May 31, 2017 09:58
winapi-rs invalid handle in union
[package]
name = "handletest"
version = "0.1.0"
authors = ["Peter Atashian <retep998@gmail.com>"]
[dependencies.winapi]
git = "https://github.com/retep998/winapi-rs"
branch = "dev"
features = ["minwinbase", "minwindef", "processthreadsapi", "winbase", "winnt"]
> cargo rustc --features everything -- -Ztime-passes
Compiling winapi v0.3.0-alpha.0 (file:///C:/Users/Peter/Code/winapi-rs)
time: 0.469; rss: 66MB parsing
time: 0.000; rss: 66MB recursion limit
time: 0.000; rss: 66MB crate injection
time: 0.000; rss: 66MB plugin loading
time: 0.000; rss: 66MB plugin registration
time: 1.858; rss: 140MB expansion
time: 0.000; rss: 140MB maybe building test harness
time: 0.023; rss: 140MB maybe creating a macro crate
@retep998
retep998 / sizes.md
Created March 9, 2017 15:29
Sizes of functions in naive hello world with rustc main.rs -O -g -Cpanic=abort -Clto
Name Size
std__panicking__default_hook____closure__ 000025E4
std__panicking__rust_panic_with_hook 00000E60
main 000008FB
std__io__Write__write_fmt____impl____write_str_std__io__stdio__StdoutLock_ 000008C5
core__fmt__Formatter__pad_integral 000005B4
std__io__error____impl____fmt 0000056C
core__fmt____impl____fmt_0 00000438
core__fmt__Formatter__pad 00000437
@retep998
retep998 / blah.md
Created November 25, 2016 04:52
winapi DST requirements

Need to be able to add dynamically sized arrays as the last field of a type.

#[repr(C)] struct Foo {
    blah: Blah,
    cbSize: DWORD,
    array: [SomeType; N], // This field should be dynamically sized.
}

The user must be able to specify a value for N when creating such a type, but there must only be one such type, so that FFI functions can easily take a *const Foo or *mut Foo.

Microsoft (R) COFF/PE Dumper Version 14.00.24215.1
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file cdylib gnu.dll
File Type: DLL
Section contains the following exports for cdylib.dll