Skip to content

Instantly share code, notes, and snippets.

@klutzy
klutzy / trace.rs
Last active December 31, 2015 14:19
#[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 / main.rs
Last active January 3, 2016 08:58
broken dependency graph impl
#[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;
@klutzy
klutzy / Makefile
Last active August 29, 2015 13:56
rust struct abi
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 / Makefile
Last active April 6, 2016 13:41
Rust/C++ ffi
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 / hello.rs
Last active August 29, 2015 14:05
// 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() {}