Skip to content

Instantly share code, notes, and snippets.

View hello.rs
// let's build rust program with msvc linker!
#![feature(intrinsics, lang_items)]
#![no_std]
#![no_main]
// (this is not required for msvc, but for "standard" build.)
#[no_mangle]
pub extern "C" fn rust_stack_exhausted() {}
@klutzy
klutzy / Makefile
Last active Apr 6, 2016
Rust/C++ ffi
View Makefile
all: a
a: a.rs libda.so
rustc a.rs -o $@ -L .
libda.so: da.cpp
clang++ $< -fPIC -shared -o $@
run: a libda.so
LD_LIBRARY_PATH=. ./a
@klutzy
klutzy / Makefile
Last active Aug 29, 2015
rust struct abi
View Makefile
all: c.dll rs.exe cl.exe hand.exe
c.dll: c.c
gcc -shared -o $@ $<
rs.exe: rs.rs
rustc --opt-level=0 -Z no-opt -L . $< -o rs.ll --emit ir
rustc --opt-level=0 -Z no-opt -L . $< -o rs.s --emit asm
rustc --opt-level=0 -Z no-opt -L . $< -o $@ -C save-temps
@klutzy
klutzy / main.rs
Last active Jan 3, 2016
broken dependency graph impl
View main.rs
#[feature(managed_boxes)];
extern mod extra;
extern mod syntax;
extern mod rustc;
use std::os::args;
use std::hashmap::{HashMap, HashSet};
use syntax::ast;
use syntax::ast_map;
View trace.rs
#[cfg(unix)]
fn trace(n_frames: uint) -> ~[~str] {
use std::libc::{c_void, c_int, c_char};
use std::libc;
use std::c_str;
use std::ptr;
use std::vec;
extern {
fn backtrace(buffer: *mut *mut c_void, size: c_int) -> c_int;
@klutzy
klutzy / hello.windows.rs
Created Dec 6, 2013
Rust with Emscripten and win32.js
View hello.windows.rs
// From rust get `libstd/libc.rs` to the working dir.
// From rust-windows <https://github.com/klutzy/rust-windows>
// copy whole `ll/` dir to the working dir and
// patch some code: (TODO)
// From win32.js <https://github.com/klutzy/win32.js>, copy
// `library_win32.js` and `window.js` to working dir.
//
// emscripten uses le32-unknown-nacl triple but rustc doesn't know it now.
// So just use similar target instead.
// Here I use `win32` because libc.rs needs it.
@klutzy
klutzy / hello.rs
Last active Apr 26, 2016
Rust with Emscripten
View hello.rs
// emscripten uses le32-unknown-nacl triple but rustc doesn't know it now.
// So just use similar target instead.
// `rustc hello.rs --target=i686-unknown-linux --emit-llvm -S --cfg libc`
// `emcc hello.ll -o hello.js`
// no `extern mod`.
#[no_std];
#[feature(macro_rules)];
use core::container::Container;
@klutzy
klutzy / gist:7627128
Created Nov 24, 2013
rust on mingw-w64: 64-bit / 32-bit comparison
View gist:7627128
# win64; host = target = x86_64-w64-mingw32
$ rustc.exe ~/stone/rust/src/libstd/lib.rs -Z time-passes
time: 25.673 s parsing
time: 0.136 s gated feature checking
time: 0.051 s std macros injection
time: 0.209 s configuration 1
time: 17.854 s expansion
time: 0.322 s configuration 2
time: 0.304 s maybe building test harness
time: 0.000 s std injection
@klutzy
klutzy / gist:7459581
Created Nov 14, 2013
rustpkg test failure on windows
View gist:7459581
$ make check-stage2-T-i686-pc-mingw32-H-i686-pc-mingw32-rustpkg
cfg: build triple i686-pc-mingw32
cfg: host triples i686-pc-mingw32
cfg: target triples i686-pc-mingw32
cfg: enabling more debugging (CFG_ENABLE_DEBUG)
cfg: host for i686-pc-mingw32 is i386
cfg: os for i686-pc-mingw32 is pc-mingw32
cfg: using gcc
cfg: disabling valgrind due to its unreliability on this platform
View gist:7450792
use std::os;
use std::io;
use std::io::fs;
fn main() {
let tmp_path = os::tmpdir();
for i in range(0u, 20u) {
let path = tmp_path.join(i.to_str());
do spawn {
io::result(|| fs::mkdir(&path, io::UserRWX));