Last active
January 9, 2018 14:44
-
-
Save retep998/e7569294e89c28dea9d2 to your computer and use it in GitHub Desktop.
Linking Rust using LLVM and MSVC. No MinGW at all.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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" | |
*/ | |
#![feature(globs, lang_items)] | |
#![no_std] | |
#![no_main] | |
extern crate core; | |
use core::prelude::*; | |
#[lang = "begin_unwind"] | |
pub extern "C" fn rust_begin_unwind(_: &core::fmt::Arguments, _: &'static str, _: uint) -> ! { loop {} } | |
#[lang = "stack_exhausted"] | |
pub extern "C" fn rust_stack_exhausted() {} | |
#[lang = "eh_personality"] | |
fn rust_eh_personality() {} | |
#[no_mangle] | |
pub extern "C" fn __morestack() {} | |
#[no_mangle] | |
pub extern "C" fn __powisf2(mut a: f32, mut b: i32) -> f32 { | |
let recip = b < 0; | |
let mut r = 1.; | |
loop { | |
if b & 1 != 0 { r *= a } | |
b /= 2; | |
if b == 0 { break } | |
a *= a; | |
} | |
if recip { r.recip() } else { r } | |
} | |
#[no_mangle] | |
pub extern "C" fn __powidf2(mut a: f64, mut b: i32) -> f64 { | |
let recip = b < 0; | |
let mut r = 1.; | |
loop { | |
if b & 1 != 0 { r *= a } | |
b /= 2; | |
if b == 0 { break } | |
a *= a; | |
} | |
if recip { r.recip() } else { r } | |
} | |
#[no_mangle] | |
pub extern "C" fn main(_argc: int, _argv: *const *const u8) -> int { | |
mymain(); | |
0 | |
} | |
fn mymain() { | |
display("Hello World!\0"); | |
} | |
fn display(s: &str) { | |
extern "system" { | |
fn MessageBoxA(hWnd: u32, lpText: *const u8, lpCaption: *const u8, uType: u32) -> i32; | |
} | |
let b = s.as_ptr(); | |
unsafe { | |
MessageBoxA(0, b, b, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment