Upgraded to latest rust

This commit is contained in:
Coeuvre 2014-05-26 15:47:36 +08:00
parent 359f197e52
commit 5bf12185a8
3 changed files with 122 additions and 114 deletions

224
Makefile
View file

@ -25,8 +25,8 @@
SHELL := /bin/bash
# The default make command.
# Change this to 'make lib' if you are building a library.
DEFAULT = make exe
# Change this to 'lib' if you are building a library.
DEFAULT = exe
EXAMPLE_FILES = examples/*.rs
SOURCE_FILES = $(shell test -e src/ && find src -type f)
@ -56,12 +56,16 @@ RLIB = target/$(TARGET)/lib/$(RLIB_FILE)
DYLIB_FILE = $(shell (rustc --crate-type=dylib --crate-file-name "src/lib.rs" 2> /dev/null) || (echo "dummy.dylib"))
DYLIB = target/$(TARGET)/lib/$(DYLIB_FILE)
all:
$(DEFAULT)
ifdef VERBOSE
Q :=
else
Q := @
endif
all: $(DEFAULT)
help:
clear \
&& echo "--- rust-empty (0.3 005)" \
$(Q)echo "--- rust-empty (0.3 005)" \
&& echo "make run - Runs executable" \
&& echo "make exe - Builds main executable" \
&& echo "make lib - Both static and dynamic library" \
@ -115,8 +119,7 @@ help:
test-external
nightly-install:
clear \
&& cd ~ \
$(Q)cd ~ \
&& curl -s http://www.rust-lang.org/rustup.sh > rustup.sh \
&& ( \
echo "Rust install-script stored as '~/rustup.sh'" ; \
@ -129,8 +132,7 @@ nightly-install:
)
nightly-uninstall:
clear \
&& cd ~ \
$(Q)cd ~ \
&& curl -s http://www.rust-lang.org/rustup.sh > rustup.sh \
&& ( \
echo "Rust install-script stored as '~/rustup.sh'" ; \
@ -143,37 +145,32 @@ nightly-uninstall:
)
cargo-lite-exe: src/main.rs
( \
$(Q)( \
test -e cargo-lite.conf \
&& clear \
&& echo "--- The file 'cargo-lite.conf' already exists" \
) \
|| \
( \
echo -e "deps = [\n]\n\n[build]\ncrate_root = \"src/main.rs\"\nrustc_args = []\n" > cargo-lite.conf \
&& clear \
&& echo "--- Created 'cargo-lite.conf' for executable" \
&& cat cargo-lite.conf \
)
cargo-lite-lib: src/lib.rs
( \
$(Q)( \
test -e cargo-lite.conf \
&& clear \
&& echo "--- The file 'cargo-lite.conf' already exists" \
) \
|| \
( \
echo -e "deps = [\n]\n\n[build]\ncrate_root = \"src/lib.rs\"\ncrate_type = \"library\"\nrustc_args = []\n" > cargo-lite.conf \
&& clear \
&& echo "--- Created 'cargo-lite.conf' for library" \
&& cat cargo-lite.conf \
)
cargo-exe: src/main.rs
( \
$(Q)( \
test -e Cargo.toml \
&& clear \
&& echo "--- The file 'Cargo.toml' already exists" \
) \
|| \
@ -181,15 +178,13 @@ cargo-exe: src/main.rs
name=$${PWD##/*/} ; \
readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \
echo -e "[project]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name <your@email.com>\"]\ntags = []\n\n[[bin]]\n\nname = \"$$name\"\npath = \"bin/main.rs\"\n" > Cargo.toml \
&& clear \
&& echo "--- Created 'Cargo.toml' for executable" \
&& cat Cargo.toml \
)
cargo-lib: src/main.rs
( \
$(Q)( \
test -e Cargo.toml \
&& clear \
&& echo "--- The file 'Cargo.toml' already exists" \
) \
|| \
@ -197,147 +192,121 @@ cargo-lib: src/main.rs
name=$${PWD##/*/} ; \
readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \
echo -e "[project]\n\nname = \"$$name\"\nversion = \"0.0\"\n$$readme\nauthors = [\"Your Name <your@email.com>\"]\ntags = []\n\n[[lib]]\n\nname = \"$$name\"\npath = \"bin/lib.rs\"\n" > Cargo.toml \
&& clear \
&& echo "--- Created 'Cargo.toml' for executable" \
&& cat Cargo.toml \
)
rust-ci-lib: src/lib.rs
( \
$(Q)( \
test -e .travis.yml \
&& clear \
&& echo "--- The file '.travis.yml' already exists" \
) \
|| \
( \
echo -e "before_install:\n\t- yes | sudo add-apt-repository ppa:hansjorg/rust\n\t- sudo apt-get update\ninstall:\n\t- sudo apt-get install rust-nightly\nscript:\n\t- make lib\n" > .travis.yml \
&& clear \
&& echo "--- Created '.travis.yml' for library" \
&& cat .travis.yml \
)
rust-ci-exe: src/main.rs
( \
$(Q)( \
test -e .travis.yml \
&& clear \
&& echo "--- The file '.travis.yml' already exists" \
) \
|| \
( \
echo -e "before_install:\n\t- yes | sudo add-apt-repository ppa:hansjorg/rust\n\t- sudo apt-get update\ninstall:\n\t- sudo apt-get install rust-nightly\nscript:\n\t- make exe\n" > .travis.yml \
&& clear \
&& echo "--- Created '.travis.yml' for executable" \
&& cat .travis.yml \
)
doc: $(SOURCE_FILES) | src/
clear \
&& $(RUSTDOC) src/lib.rs -L "target/$(TARGET)/lib" \
&& clear \
$(Q)$(RUSTDOC) src/lib.rs -L "target/$(TARGET)/lib" \
&& echo "--- Built documentation"
run: exe
clear \
&& cd bin/ \
$(Q)cd bin/ \
&& ./main
exe: bin/main | $(TARGET_LIB_DIR)
bin/main: $(SOURCE_FILES) | bin/ src/main.rs
clear \
&& $(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) src/main.rs -o bin/main -L "target/$(TARGET)/lib" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) src/main.rs -o bin/main -L "target/$(TARGET)/lib" \
&& echo "--- Built executable" \
&& echo "--- Type 'make run' to run executable"
test: test-internal test-external
clear \
&& echo "--- Internal tests succeeded" \
$(Q)echo "--- Internal tests succeeded" \
&& echo "--- External tests succeeded"
test-external: bin/test-external
cd "bin/" \
$(Q)cd "bin/" \
&& ./test-external
bin/test-external: $(SOURCE_FILES) | rlib bin/ src/test.rs
clear \
&& $(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/$(TARGET)/lib" \
&& echo "--- Built external test runner"
test-internal: bin/test-internal
cd "bin/" \
$(Q)cd "bin/" \
&& ./test-internal
bin/test-internal: $(SOURCE_FILES) | rlib src/ bin/
clear \
&& $(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test src/lib.rs -o bin/test-internal -L "target/$(TARGET)/lib" \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test src/lib.rs -o bin/test-internal -L "target/$(TARGET)/lib" \
&& echo "--- Built internal test runner"
bench: bench-internal bench-external
bench-external: test-external
clear \
&& bin/test-external --bench
$(Q)bin/test-external --bench
bench-internal: test-internal
clear \
&& bin/test-internal --bench
$(Q)bin/test-internal --bench
lib: rlib dylib
clear \
&& echo "--- Built rlib" \
&& echo "--- Built dylib" \
&& echo "--- Type 'make test' to test library"
$(Q)echo "--- Type 'make test' to test library"
rlib: $(RLIB)
$(RLIB): $(SOURCE_FILES) | src/lib.rs $(TARGET_LIB_DIR)
clear \
&& $(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=rlib src/lib.rs -L "target/$(TARGET)/lib" --out-dir "target/$(TARGET)/lib/" \
&& clear \
&& echo "--- Built rlib" \
&& echo "--- Type 'make test' to test library"
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=rlib src/lib.rs -L "target/$(TARGET)/lib" --out-dir "target/$(TARGET)/lib/" \
&& echo "--- Built rlib"
dylib: $(DYLIB)
$(DYLIB): $(SOURCE_FILES) | src/lib.rs $(TARGET_LIB_DIR)
clear \
&& $(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=dylib src/lib.rs -L "target/$(TARGET)/lib" --out-dir "target/$(TARGET)/lib/" \
&& clear \
&& echo "--- Built dylib" \
&& echo "--- Type 'make test' to test library"
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=dylib src/lib.rs -L "target/$(TARGET)/lib" --out-dir "target/$(TARGET)/lib/" \
&& echo "--- Built dylib"
bin:
mkdir -p bin
$(Q)mkdir -p bin
$(TARGET_LIB_DIR):
mkdir -p $(TARGET_LIB_DIR)
$(Q)mkdir -p $(TARGET_LIB_DIR)
src:
mkdir -p src
$(Q)mkdir -p src
examples-dir:
test -e examples \
$(Q)test -e examples \
|| \
( \
mkdir examples \
&& echo -e "fn main() {\n\tprintln!(\"Hello!\");\n}\n" > examples/hello.rs \
&& clear \
&& echo "--- Created examples folder" \
)
rust-dir:
mkdir -p .rust
$(Q)mkdir -p .rust
git-ignore:
( \
$(Q)( \
test -e .gitignore \
&& clear \
&& echo "--- The file '.gitignore' already exists" \
) \
|| \
( \
echo -e ".DS_Store\n*~\n*#\n*.o\n*.so\n*.swp\n*.dylib\n*.dSYM\n*.dll\n*.rlib\n*.dummy\n*.exe\n*-test\n/bin/main\n/bin/test-internal\n/bin/test-external\n/doc/\n/target/\n/build/\n/.rust/\nrusti.sh\n" > .gitignore \
&& clear \
&& echo "--- Created '.gitignore' for git" \
&& cat .gitignore \
)
@ -345,88 +314,130 @@ git-ignore:
examples: $(EXAMPLE_FILES)
$(EXAMPLE_FILES): lib examples-dir
$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $@ -L "target/$(TARGET)/lib" --out-dir examples/ \
&& clear \
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $@ -L "target/$(TARGET)/lib" --out-dir examples/ \
&& echo "--- Built examples"
src/main.rs: | src/
test -e src/main.rs \
$(Q)test -e src/main.rs \
|| \
( \
echo -e "fn main() {\n\tprintln!(\"Hello world!\");\n}" > src/main.rs \
)
src/test.rs: | src/
test -e src/test.rs \
$(Q)test -e src/test.rs \
|| \
( \
touch src/test.rs \
)
src/lib.rs: | src/
test -e src/lib.rs \
$(Q)test -e src/lib.rs \
|| \
( \
echo -e "#![crate_id = \"\"]\n#![deny(missing_doc)]\n\n//! Documentation goes here.\n" > src/lib.rs \
)
clean:
rm -f "$(RLIB)"
rm -f "$(DYLIB)"
rm -rf "doc/"
rm -f "bin/main"
rm -f "bin/test-internal"
rm -f "bin/test-external"
clear \
&& echo "--- Deleted binaries and documentation"
$(Q)rm -f "$(RLIB)"
$(Q)rm -f "$(DYLIB)"
$(Q)rm -rf "doc/"
$(Q)rm -f "bin/main"
$(Q)rm -f "bin/test-internal"
$(Q)rm -f "bin/test-external"
$(Q)echo "--- Deleted binaries and documentation"
clear-project:
rm -f ".symlink-info"
rm -f "cargo-lite.conf"
rm -f ".travis.yml"
rm -f "rusti.sh"
rm -rf "target/"
rm -rf "src/"
rm -rf "bin/"
rm -rf "examples/"
rm -rf "doc/"
clear \
&& echo "--- Removed all source files, binaries and documentation" \
$(Q)rm -f ".symlink-info"
$(Q)rm -f "cargo-lite.conf"
$(Q)rm -f ".travis.yml"
$(Q)rm -f "rusti.sh"
$(Q)rm -rf "target/"
$(Q)rm -rf "src/"
$(Q)rm -rf "bin/"
$(Q)rm -rf "examples/"
$(Q)rm -rf "doc/"
$(Q)echo "--- Removed all source files, binaries and documentation" \
&& echo "--- Content in project folder" \
&& ls -a
clear-git:
rm -f ".gitignore"
rm -rf ".git"
clear \
&& echo "--- Removed Git" \
$(Q)rm -f ".gitignore"
$(Q)rm -rf ".git"
$(Q)echo "--- Removed Git" \
&& echo "--- Content in project folder" \
&& ls -a
# borrowed from http://stackoverflow.com/q/649246/1256624
define RUSTI_SCRIPT
#!/bin/bash
#written by mcpherrin
while true; do
echo -n "> "
read line
TMP="`mktemp r.XXXXXX`"
$(COMPILER) - -o $$TMP -L "target/$(TARGET)/lib/" <<EOF
#![feature(globs, macro_rules, phase, struct_variant)]
extern crate arena;
extern crate collections;
extern crate flate;
#[phase(syntax)] extern crate fourcc;
extern crate glob;
extern crate green;
extern crate hexfloat;
extern crate libc;
#[phase(syntax, link)] extern crate log;
extern crate native;
extern crate num;
extern crate rand;
extern crate rustc;
extern crate rustdoc;
extern crate rustuv;
extern crate semver;
extern crate serialize;
extern crate sync;
extern crate syntax;
extern crate term;
extern crate test;
extern crate time;
extern crate url;
extern crate uuid;
extern crate workcache;
fn main() {
let r = { $$line };
println!("{:?}", r);
}
EOF
./$$TMP
rm $$TMP
done
endef
export RUSTI_SCRIPT
rusti: $(TARGET_LIB_DIR)
( \
$(Q)( \
test -e rusti.sh \
&& clear \
&& echo "--- The file 'rusti.sh' already exists" \
) \
|| \
( \
echo -e "#!/bin/bash\n\n#written by mcpherrin\n\nwhile true; do\n echo -n \"> \"\n read line\n TMP=\"`mktemp r.XXXXXX`\"\n $(COMPILER) - -o \$$TMP -L "target/$(TARGET)/lib/" <<EOF\n #![feature(globs, macro_rules, phase, struct_variant)]\n extern crate arena;\n extern crate collections;\n extern crate flate;\n #[phase(syntax)] extern crate fourcc;\n extern crate glob;\n extern crate green;\n extern crate hexfloat;\n extern crate libc;\n #[phase(syntax, link)] extern crate log;\n extern crate native;\n extern crate num;\n extern crate rand;\n extern crate rustc;\n extern crate rustdoc;\n extern crate rustuv;\n extern crate semver;\n extern crate serialize;\n extern crate sync;\n extern crate syntax;\n extern crate term;\n extern crate test;\n extern crate time;\n extern crate url;\n extern crate uuid;\n extern crate workcache;\n\n fn main() {\n let r = { \$$line };\n println!(\"{:?}\", r);\n }\nEOF\n ./\$$TMP\n rm \$$TMP\ndone" > rusti.sh \
echo -e "$$RUSTI_SCRIPT" > rusti.sh \
&& chmod +x rusti.sh \
&& clear \
&& echo "--- Created 'rusti.sh'" \
&& echo "--- Type './rusti.sh' to start interactive Rust" \
)
loc:
clear \
&& echo "--- Counting lines of .rs files in 'src' (LOC):" \
$(Q)echo "--- Counting lines of .rs files in 'src' (LOC):" \
&& find src/ -type f -name "*.rs" -exec cat {} \; | wc -l
# Finds the original locations of symlinked libraries and
# prints the commit hash with remote branches containing that commit.
symlink-info:
current=$$(pwd) ; \
$(Q) current=$$(pwd) ; \
for symlib in $$(find target/*/lib -type l) ; do \
cd $$current ; \
echo $$symlib ; \
@ -441,8 +452,5 @@ symlink-info:
done \
> .symlink-info \
&& cd $$current \
&& clear \
&& echo "--- Created '.symlink-info'" \
&& cat .symlink-info

View file

@ -27,7 +27,7 @@ impl<'a> Game for App<'a> {
self.number_renderer = Some(NumberRenderer::new(asset_store));
}
fn render(&self, c: &Context, gl: &mut Gl) {
fn render(&self, _ext_dt: f64, c: &Context, gl: &mut Gl) {
self.board.render(self.number_renderer.get_ref(), c, gl);
}

View file

@ -11,7 +11,7 @@ use serialize::{
static SETTING_FILENAME: &'static str = "settings.json";
pub struct Settings {
pub asset_folder: StrBuf,
pub asset_folder: String,
pub window_size: [u32, ..2],
pub window_background_color: [f32, ..3],
pub board_padding: f64,
@ -125,7 +125,7 @@ impl Settings {
#[deriving(Encodable, Decodable)]
struct SettingsInJson {
asset_folder: StrBuf,
asset_folder: String,
// r g b (0 - 255)
window_background_color: Vec<f32>,
@ -220,12 +220,12 @@ impl SettingsInJson {
}
pub fn save(&self) {
let exe_path = self_exe_path().unwrap();
let exe_path = self_exe_path();
if exe_path.is_none() {
println!("WARNING: Failed to save settings: can't find exe path.");
return;
}
let path = exe_path.join(Path::new(SETTING_FILENAME));
let path = exe_path.unwrap().join(Path::new(SETTING_FILENAME));
let file = File::create(&path).unwrap();
let mut writer = BufferedWriter::new(file);
let mut encoder = json::Encoder::new(&mut writer);