Merge pull request #11 from bvssvni/master

Upgraded to latest Rust + Rust-Empty
This commit is contained in:
ShuYu Wang
2014-06-30 20:57:32 +08:00
4 changed files with 146 additions and 65 deletions
+24 -21
View File
@@ -68,20 +68,20 @@ endif
RUSTDOC = rustdoc
# Extracts target from rustc.
TARGET = $(shell rustc --version 2> /dev/null | awk "/host:/ { print \$$2 }")
TARGET = $(shell rustc --version verbose 2> /dev/null | awk "/host:/ { print \$$2 }")
# TARGET = x86_64-unknown-linux-gnu
# TARGET = x86_64-apple-darwin
TARGET_LIB_DIR = target/$(TARGET)/lib/
TARGET_LIB_DIR = target/deps/
# Ask 'rustc' the file name of the library and use a dummy name if the source has not been created yet.
# The dummy file name is used to trigger the creation of the source first time.
# Next time 'rustc' will return the right file name.
RLIB_FILE = $(shell (rustc --crate-type=rlib --crate-file-name "$(LIB_ENTRY_FILE)" 2> /dev/null) || (echo "dummy.rlib"))
# You can't have quotes around paths because 'make' doesn't see it exists.
RLIB = target/$(TARGET)/lib/$(RLIB_FILE)
RLIB = target/$(RLIB_FILE)
DYLIB_FILE = $(shell (rustc --crate-type=dylib --crate-file-name "$(LIB_ENTRY_FILE)" 2> /dev/null) || (echo "dummy.dylib"))
DYLIB = target/$(TARGET)/lib/$(DYLIB_FILE)
DYLIB = target/$(DYLIB_FILE)
# Use 'VERBOSE=1' to echo all commands, for example 'make help VERBOSE=1'.
ifdef VERBOSE
@@ -93,7 +93,7 @@ endif
all: $(DEFAULT)
help:
$(Q)echo "--- rust-empty (0.5 007)"
$(Q)echo "--- rust-empty (0.6 003)"
$(Q)echo "make run - Runs executable"
$(Q)echo "make exe - Builds main executable"
$(Q)echo "make lib - Both static and dynamic library"
@@ -110,8 +110,8 @@ help:
$(Q)echo "make examples - Builds examples"
$(Q)echo "make cargo-lite-exe - Setup executable package"
$(Q)echo "make cargo-lite-lib - Setup library package"
$(Q)echo "make cargo-exe - EXPERIMENTAL: Setup executable package"
$(Q)echo "make cargo-lib - EXPERIMENTAL: Setup library package"
$(Q)echo "make cargo-exe - Setup executable package"
$(Q)echo "make cargo-lib - Setup library package"
$(Q)echo "make rust-ci-lib - Setup Travis CI Rust library"
$(Q)echo "make rust-ci-exe - Setup Travis CI Rust executable"
$(Q)echo "make rusti - Setup 'rusti.sh' for interactive Rust"
@@ -211,12 +211,12 @@ cargo-exe: $(EXE_ENTRY_FILE)
( \
name=$${PWD##/*/} ; \
readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \
echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name <your@email.com>\"]\ntags = []\n\n[[bin]]\n\nname = \"$$name\"\npath = \"$(EXE_ENTRY_FILE)\"\n" > Cargo.toml \
echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0.0\"\n$$readme\nauthors = [\"Your Name <your@email.com>\"]\ntags = []\n\n[[bin]]\n\nname = \"$$name\"\npath = \"$(EXE_ENTRY_FILE)\"\n" > Cargo.toml \
&& echo "--- Created 'Cargo.toml' for executable" \
&& cat Cargo.toml \
)
cargo-lib: $(EXE_ENTRY_FILE)
cargo-lib: $(LIB_ENTRY_FILE)
$(Q)( \
test -e Cargo.toml \
&& echo "--- The file 'Cargo.toml' already exists" \
@@ -225,7 +225,7 @@ cargo-lib: $(EXE_ENTRY_FILE)
( \
name=$${PWD##/*/} ; \
readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \
echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name <your@email.com>\"]\ntags = []\n\n[[lib]]\n\nname = \"$$name\"\npath = \"$(LIB_ENTRY_FILE)\"\n" > Cargo.toml \
echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0.0\"\n$$readme\nauthors = [\"Your Name <your@email.com>\"]\ntags = []\n\n[[lib]]\n\nname = \"$$name\"\npath = \"$(LIB_ENTRY_FILE)\"\n" > Cargo.toml \
&& echo "--- Created 'Cargo.toml' for executable" \
&& cat Cargo.toml \
)
@@ -255,7 +255,7 @@ rust-ci-exe: $(EXE_ENTRY_FILE)
)
doc: $(SOURCE_FILES) | src/
$(Q)$(RUSTDOC) $(LIB_ENTRY_FILE) -L "target/$(TARGET)/lib" \
$(Q)$(RUSTDOC) $(LIB_ENTRY_FILE) -L "$(TARGET_LIB_DIR)" \
&& echo "--- Built documentation"
run: exe
@@ -267,7 +267,7 @@ target-dir: $(TARGET_LIB_DIR)
exe: bin/main | $(TARGET_LIB_DIR)
bin/main: $(SOURCE_FILES) | bin/ $(EXE_ENTRY_FILE)
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $(EXE_ENTRY_FILE) -o bin/main -L "target/$(TARGET)/lib" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $(EXE_ENTRY_FILE) -o bin/main -L "$(TARGET_LIB_DIR)" -L "target" \
&& echo "--- Built executable" \
&& echo "--- Type 'make run' to run executable"
@@ -280,7 +280,7 @@ test-external: bin/test-external
&& ./test-external
bin/test-external: $(SOURCE_FILES) | rlib bin/ src/test.rs
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test src/test.rs -o bin/test-external -L "target/$(TARGET)/lib" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test src/test.rs -o bin/test-external -L "$(TARGET_LIB_DIR)" -L "target" \
&& echo "--- Built external test runner"
test-internal: bin/test-internal
@@ -288,7 +288,7 @@ test-internal: bin/test-internal
&& ./test-internal
bin/test-internal: $(SOURCE_FILES) | rlib src/ bin/
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test $(LIB_ENTRY_FILE) -o bin/test-internal -L "target/$(TARGET)/lib" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test $(LIB_ENTRY_FILE) -o bin/test-internal -L "$(TARGET_LIB_DIR)" -L "target" \
&& echo "--- Built internal test runner"
bench: bench-internal bench-external
@@ -305,13 +305,13 @@ lib: rlib dylib
rlib: $(RLIB)
$(RLIB): $(SOURCE_FILES) | $(LIB_ENTRY_FILE) $(TARGET_LIB_DIR)
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=rlib $(LIB_ENTRY_FILE) -L "target/$(TARGET)/lib" --out-dir "target/$(TARGET)/lib/" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=rlib $(LIB_ENTRY_FILE) -L "$(TARGET_LIB_DIR)" --out-dir "target" \
&& echo "--- Built rlib"
dylib: $(DYLIB)
$(DYLIB): $(SOURCE_FILES) | $(LIB_ENTRY_FILE) $(TARGET_LIB_DIR)
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=dylib $(LIB_ENTRY_FILE) -L "target/$(TARGET)/lib" --out-dir "target/$(TARGET)/lib/" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=dylib $(LIB_ENTRY_FILE) -L "$(TARGET_LIB_DIR)" --out-dir "target/" \
&& echo "--- Built dylib"
bin/:
@@ -350,7 +350,7 @@ git-ignore:
examples: $(EXAMPLE_FILES)
$(EXAMPLE_FILES): lib examples-dir
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $@ -L "target/$(TARGET)/lib" --out-dir examples/ \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $@ -L "$(TARGET_LIB_DIR)" -L "target" --out-dir examples/ \
&& echo "--- Built '$@' (make $@)"
$(EXE_ENTRY_FILE): | src/
@@ -416,7 +416,7 @@ while true; do
echo -n "> "
read line
TMP="`mktemp r.XXXXXX`"
$(COMPILER) - -o $$TMP -L "target/$(TARGET)/lib/" <<EOF
$(COMPILER) - -o $$TMP -L "$(TARGET_LIB_DIR)" <<EOF
#![feature(globs, macro_rules, phase, struct_variant)]
extern crate arena;
extern crate collections;
@@ -585,7 +585,7 @@ function contains() {
i=0
function build_deps {
local current=$$(pwd)
for symlib in $$(find target/*/lib -type l) ; do
for symlib in $$(find $(TARGET_LIB_DIR) -type l) ; do
cd $$current
echo $$symlib
local original_file=$$(readlink $$symlib)
@@ -606,6 +606,7 @@ function build_deps {
# Remember git directory to not build it twice
git_dir[i]=$$current_git_dir
let i+=1
# Visit the symlinks and build the dependencies
build_deps
@@ -630,11 +631,13 @@ function build_deps {
&& $$MAKE clean \
&& $$MAKE \
)
let i+=1
done
cd $$current
}
# Mark main project as visited to avoid infinite loop.
git_dir[i]=$$(pwd)
let i+=1
if [ "$$1" == "deps" ]; then
build_deps
fi
@@ -675,7 +678,7 @@ loc:
# prints the commit hash with remote branches containing that commit.
symlink-info:
$(Q) current=$$(pwd) ; \
for symlib in $$(find target/*/lib -type l) ; do \
for symlib in $$(find $(TARGET_LIB_DIR) -type l) ; do \
cd $$current ; \
echo $$symlib ; \
original_file=$$(readlink $$symlib) ; \
Executable
+78
View File
@@ -0,0 +1,78 @@
#!/bin/bash
# written by bvssvni
# Modify the setting to do conditional compilation.
# For example "--cfg my_feature"
SETTINGS=""
# ================================================
MAKE=make
if [ "$OS" == "Windows_NT" ]; then
MAKE=mingw32-make
fi
# Checks if an item exists in an array.
# Copied from http://stackoverflow.com/questions/3685970/check-if-an-array-contains-a-value
function contains() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [ "${!i}" == "${value}" ]; then
echo "y"
return 0
fi
}
echo "n"
return 1
}
# This is a counter used to insert dependencies.
# It is global because we need an array of all the
# visited dependencies.
i=0
function build_deps {
local current=$(pwd)
for symlib in $(find target/deps/ -type l) ; do
cd $current
echo $symlib
local original_file=$(readlink $symlib)
local original_dir=$(dirname $original_file)
cd $original_dir
# Go to the git root directory.
local current_git_dir=$(git rev-parse --show-toplevel)
echo "--- Parent $current"
echo "--- Child $current_git_dir"
cd $current_git_dir
# Skip building if it is already built.
if [ $(contains "${git_dir[@]}" $current_git_dir) == "y" ]; then
echo "--- Visited $current_git_dir"
continue
fi
# Remember git directory to not build it twice
git_dir[i]=$current_git_dir
let i+=1
# Visit the symlinks and build the dependencies
build_deps
# First check for a 'build.sh' script with default settings.
# Check for additional 'rust-empty.mk' file. # Compile with the settings flags. # If no other options, build with make.
( test -e build.sh && ./build.sh ) || ( test -e rust-empty.mk && $MAKE -f rust-empty.mk clean && $MAKE -f rust-empty.mk ) || ( echo "--- Building $current_git_dir" && $MAKE clean && $MAKE )
done
cd $current
}
# Mark main project as visited to avoid infinite loop.
git_dir[i]=$(pwd)
let i+=1
if [ "$1" == "deps" ]; then
build_deps
fi
echo "--- Building $(pwd)"
( test -e rust-empty.mk && $MAKE -f rust-empty.mk clean && $MAKE -f rust-empty.mk COMPILER_FLAGS+="$SETTINGS" ) || ( $MAKE clean
$MAKE COMPILER_FLAGS+="$SETTINGS"
)
+42 -42
View File
@@ -13,7 +13,7 @@ pub static MIX_INIT_OGG: c_uint = 16;
pub static MIX_INIT_FLUIDSYNTH: c_uint = 32;
pub struct Struct_Mix_Chunk {
pub allocated: c_int,
pub abuf: *uint8_t,
pub abuf: *const uint8_t,
pub alen: uint32_t,
pub volume: uint8_t,
}
@@ -37,55 +37,55 @@ pub type Struct__Mix_Music = c_void;
pub type Mix_Music = Struct__Mix_Music;
pub type Mix_EffectFunc_t =
::std::option::Option<extern "C" fn
(arg1: c_int, arg2: *c_void, arg3: c_int,
arg4: *c_void)>;
(arg1: c_int, arg2: *const c_void, arg3: c_int,
arg4: *const c_void)>;
pub type Mix_EffectDone_t =
::std::option::Option<extern "C" fn(arg1: c_int, arg2: *c_void)>;
::std::option::Option<extern "C" fn(arg1: c_int, arg2: *const c_void)>;
extern "C" {
pub fn Mix_Linked_Version() -> *SDL_version;
pub fn Mix_Linked_Version() -> *const SDL_version;
pub fn Mix_Init(flags: c_int) -> c_int;
pub fn Mix_Quit();
pub fn Mix_OpenAudio(frequency: c_int, format: uint16_t, channels: c_int,
chunksize: c_int) -> c_int;
pub fn Mix_AllocateChannels(numchans: c_int) -> c_int;
pub fn Mix_QuerySpec(frequency: *c_int, format: *uint16_t,
channels: *c_int) -> c_int;
pub fn Mix_LoadWAV_RW(src: *SDL_RWops, freesrc: c_int) ->
*Mix_Chunk;
pub fn Mix_LoadMUS(file: *c_char) -> *Mix_Music;
pub fn Mix_LoadMUS_RW(src: *SDL_RWops, freesrc: c_int) ->
*Mix_Music;
pub fn Mix_LoadMUSType_RW(src: *SDL_RWops, _type: Mix_MusicType,
freesrc: c_int) -> *Mix_Music;
pub fn Mix_QuickLoad_WAV(mem: *uint8_t) -> *Mix_Chunk;
pub fn Mix_QuickLoad_RAW(mem: *uint8_t, len: uint32_t) -> *Mix_Chunk;
pub fn Mix_FreeChunk(chunk: *Mix_Chunk);
pub fn Mix_FreeMusic(music: *Mix_Music);
pub fn Mix_QuerySpec(frequency: *const c_int, format: *const uint16_t,
channels: *const c_int) -> c_int;
pub fn Mix_LoadWAV_RW(src: *const SDL_RWops, freesrc: c_int) ->
*const Mix_Chunk;
pub fn Mix_LoadMUS(file: *const c_char) -> *const Mix_Music;
pub fn Mix_LoadMUS_RW(src: *const SDL_RWops, freesrc: c_int) ->
*const Mix_Music;
pub fn Mix_LoadMUSType_RW(src: *const SDL_RWops, _type: Mix_MusicType,
freesrc: c_int) -> *const Mix_Music;
pub fn Mix_QuickLoad_WAV(mem: *const uint8_t) -> *const Mix_Chunk;
pub fn Mix_QuickLoad_RAW(mem: *const uint8_t, len: uint32_t) -> *const Mix_Chunk;
pub fn Mix_FreeChunk(chunk: *const Mix_Chunk);
pub fn Mix_FreeMusic(music: *const Mix_Music);
pub fn Mix_GetNumChunkDecoders() -> c_int;
pub fn Mix_GetChunkDecoder(index: c_int) -> *c_char;
pub fn Mix_GetChunkDecoder(index: c_int) -> *const c_char;
pub fn Mix_GetNumMusicDecoders() -> c_int;
pub fn Mix_GetMusicDecoder(index: c_int) -> *c_char;
pub fn Mix_GetMusicType(music: *Mix_Music) -> Mix_MusicType;
pub fn Mix_GetMusicDecoder(index: c_int) -> *const c_char;
pub fn Mix_GetMusicType(music: *const Mix_Music) -> Mix_MusicType;
pub fn Mix_SetPostMix(mix_func:
::std::option::Option<extern "C" fn
(arg1: *c_void,
arg2: *uint8_t,
(arg1: *const c_void,
arg2: *const uint8_t,
arg3: c_int)>,
arg: *c_void);
arg: *const c_void);
pub fn Mix_HookMusic(mix_func:
::std::option::Option<extern "C" fn
(arg1: *c_void,
arg2: *uint8_t,
(arg1: *const c_void,
arg2: *const uint8_t,
arg3: c_int)>,
arg: *c_void);
arg: *const c_void);
pub fn Mix_HookMusicFinished(music_finished:
::std::option::Option<extern "C" fn()>);
pub fn Mix_GetMusicHookData() -> *c_void;
pub fn Mix_GetMusicHookData() -> *const c_void;
pub fn Mix_ChannelFinished(channel_finished:
::std::option::Option<extern "C" fn
(arg1: c_int)>);
pub fn Mix_RegisterEffect(chan: c_int, f: Mix_EffectFunc_t,
d: Mix_EffectDone_t, arg: *c_void) -> c_int;
d: Mix_EffectDone_t, arg: *const c_void) -> c_int;
pub fn Mix_UnregisterEffect(channel: c_int, f: Mix_EffectFunc_t) -> c_int;
pub fn Mix_UnregisterAllEffects(channel: c_int) -> c_int;
pub fn Mix_SetPanning(channel: c_int, left: uint8_t, right: uint8_t) -> c_int;
@@ -100,18 +100,18 @@ extern "C" {
pub fn Mix_GroupCount(tag: c_int) -> c_int;
pub fn Mix_GroupOldest(tag: c_int) -> c_int;
pub fn Mix_GroupNewer(tag: c_int) -> c_int;
pub fn Mix_PlayChannelTimed(channel: c_int, chunk: *Mix_Chunk,
pub fn Mix_PlayChannelTimed(channel: c_int, chunk: *const Mix_Chunk,
loops: c_int, ticks: c_int) -> c_int;
pub fn Mix_PlayMusic(music: *Mix_Music, loops: c_int) -> c_int;
pub fn Mix_FadeInMusic(music: *Mix_Music, loops: c_int, ms: c_int) ->
pub fn Mix_PlayMusic(music: *const Mix_Music, loops: c_int) -> c_int;
pub fn Mix_FadeInMusic(music: *const Mix_Music, loops: c_int, ms: c_int) ->
c_int;
pub fn Mix_FadeInMusicPos(music: *Mix_Music, loops: c_int, ms: c_int,
pub fn Mix_FadeInMusicPos(music: *const Mix_Music, loops: c_int, ms: c_int,
position: c_double) -> c_int;
pub fn Mix_FadeInChannelTimed(channel: c_int, chunk: *Mix_Chunk,
pub fn Mix_FadeInChannelTimed(channel: c_int, chunk: *const Mix_Chunk,
loops: c_int, ms: c_int, ticks: c_int) ->
c_int;
pub fn Mix_Volume(channel: c_int, volume: c_int) -> c_int;
pub fn Mix_VolumeChunk(chunk: *Mix_Chunk, volume: c_int) -> c_int;
pub fn Mix_VolumeChunk(chunk: *const Mix_Chunk, volume: c_int) -> c_int;
pub fn Mix_VolumeMusic(volume: c_int) -> c_int;
pub fn Mix_HaltChannel(channel: c_int) -> c_int;
pub fn Mix_HaltGroup(tag: c_int) -> c_int;
@@ -132,17 +132,17 @@ extern "C" {
pub fn Mix_SetMusicPosition(position: c_double) -> c_int;
pub fn Mix_Playing(channel: c_int) -> c_int;
pub fn Mix_PlayingMusic() -> c_int;
pub fn Mix_SetMusicCMD(command: *c_char) -> c_int;
pub fn Mix_SetMusicCMD(command: *const c_char) -> c_int;
pub fn Mix_SetSynchroValue(value: c_int) -> c_int;
pub fn Mix_GetSynchroValue() -> c_int;
pub fn Mix_SetSoundFonts(paths: *c_char) -> c_int;
pub fn Mix_GetSoundFonts() -> *c_char;
pub fn Mix_SetSoundFonts(paths: *const c_char) -> c_int;
pub fn Mix_GetSoundFonts() -> *const c_char;
pub fn Mix_EachSoundFont(function:
::std::option::Option<extern "C" fn
(arg1: *c_char,
arg2: *c_void)
(arg1: *const c_char,
arg2: *const c_void)
-> c_int>,
data: *c_void) -> c_int;
pub fn Mix_GetChunk(channel: c_int) -> *Mix_Chunk;
data: *const c_void) -> c_int;
pub fn Mix_GetChunk(channel: c_int) -> *const Mix_Chunk;
pub fn Mix_CloseAudio();
}
+2 -2
View File
@@ -176,7 +176,7 @@ pub fn get_chunk_decoder(index: int) -> String {
/// The internal format for an audio chunk.
#[deriving(PartialEq)] #[allow(raw_pointer_deriving, visible_private_types)]
pub struct Chunk {
pub raw: *ffi::Mix_Chunk,
pub raw: *const ffi::Mix_Chunk,
pub owned: bool
}
@@ -602,7 +602,7 @@ extern "C" fn c_music_finished_hook() {
/// This is an opaque data type used for Music data.
#[deriving(PartialEq)] #[allow(raw_pointer_deriving, visible_private_types)]
pub struct Music {
pub raw: *ffi::Mix_Music,
pub raw: *const ffi::Mix_Music,
pub owned: bool,
}