> % rustc hello.rs --target=psp -lpspdebug -lpspdisplay -lpspge -lm -lc -lpspuser -lgcc
> % psp-fixup-imports hello && psp-prxgen hello hello.prx
Or what the hell do #![no_start]
, #![no_main]
, #[lang = "start"]
, #[start]
, and #[main]
do?
Disable automatically linking in the native crate and thus the default start lang item.
Which means you'll probably need one of: #![no_main]
, #![lang = “start”]
or #[start]
instead
This is a quick example of a simple TCP server written (mostly) in Rust which implements RFC 1413. It has a bit of networking, regex, and FFI.
All code examples have been written against a recent build from git: rustc 0.11-pre (9f484e6 2014-04-30 15:46:47 -0700)
To start off, how about we flesh out the general structure a little:
Steps:
- Download http://luqman.ca/rust-builds/rust-0.9-pre-191cba6-i686-w64-mingw32.zip
- Extract to somewhere, say Desktop
- Download http://sourceforge.net/projects/mingwbuilds/files/latest/download
- Run mingw-builds-install.exe
- Options you want: arch: x32, threads: win32 and exception: sjlj
- Install to somewhere, say like
C:\mingw-builds\x32-4.8.1-win32-sjlj-rev5
- Now just run
C:\mingw-builds\x32-4.8.1-win32-sjlj-rev5\mingwbuilds.bat
- Set up path:
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
#![feature(asm, macro_rules)] | |
use std::mem; | |
fn rotl(val: u64, shift: u8) -> u64 { | |
let sz = mem::size_of_val(&val); | |
(val << shift) | (val >> (sz * 8 - shift as uint)) | |
} |
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
-> % rustc foo.rs --lib -Z extra-debug-info | |
-> % ls | |
foo.c foo.rs libfoo-102129e09d96658-0.0.so | |
-> % gcc foo.c -g -L. -lfoo-102129e09d96658-0.0 -o foo | |
-> % LD_LIBRARY_PATH=. ./foo | |
[1] 30770 segmentation fault LD_LIBRARY_PATH=. ./foo |
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
extern int foobar __attribute__((weak)); | |
int main(int argc, char *argv[]) { | |
return foobar; | |
} |
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
#[simd] | |
struct F(f32, f32); | |
static A: F = F(2.0, 3.5); | |
fn main() { | |
} |
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
extern mod sdl; | |
use std::libc::{c_int, c_void}; | |
use std::rt::comm; | |
use std::rt::io::extensions::*; | |
use std::rt::io::io_error; | |
use std::rt::io::net::ip::{IpAddr, Ipv4Addr, Port, SocketAddr}; | |
use std::rt::io::net::tcp::TcpStream; | |
use std::task; | |
use std::vec; |
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
~"register_foreign_item_fn(abis=\"C\", path=[cmath, c_float_utils, ceil], foreign_item.id=153330)" | |
~"trans_native_call(callee_ty=extern \"C\" unsafe fn(f32) -> f32, llfn=*fn(Float) -> Float, llretptr=*Float)" | |
~"argument 0, llarg_rust=Float, rust_indirect=false, arg_ty=Float" | |
~"llarg_rust=*Float (after indirection)" | |
~"llarg_rust=*Float (after casting)" | |
~"argument 0, llarg_foreign=Float" | |
~"llretptr=*Float" | |
~"llforeign_retval=Float" | |
~"llrust_ret_ty=Float" | |
~"llforeign_ret_ty=Float" |