From cba62e0a637015cfc8d8e4061801b20e936d3c66 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Sun, 13 Jul 2014 14:45:03 +0200 Subject: [PATCH 1/2] Upgraded to latest Rust-Empty --- rust-empty.mk | 88 ++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 61 deletions(-) diff --git a/rust-empty.mk b/rust-empty.mk index 427a4cb0..47ba237a 100644 --- a/rust-empty.mk +++ b/rust-empty.mk @@ -1,4 +1,4 @@ -# Rust-Empty: An Makefile to get started with Rust +# Rust-Empty: A Makefile to get started with Rust # https://github.com/bvssvni/rust-empty # # The MIT License (MIT) @@ -45,26 +45,6 @@ COMPILER = rustc # For debugging: # COMPILER_FLAGS = -g -UNAME=$(shell uname) - -ifeq ($(UNAME),Darwin) - # If the user wasn't explicit, see if SDL2 library exists - ifeq ("$(strip $(SDL_MODE))","") - SDL_CHECK=$(shell pkg-config --exists sdl2 && echo $$?) - ifeq ($(SDL_CHECK),0) - SDL_MODE = dylib - else - SDL_MODE = framework - endif - endif - - ifeq ($(SDL_MODE),framework) - COMPILER_FLAGS+=--cfg mac_framework - else - COMPILER_FLAGS+=--cfg mac_dylib - endif -endif - RUSTDOC = rustdoc # Extracts target from rustc. @@ -83,6 +63,9 @@ 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/$(DYLIB_FILE) +EXE_FILE = $(shell (rustc --crate-type=bin --print-file-name "$(EXE_ENTRY_FILE)" 2> /dev/null) || (echo "main")) +EXE = bin/$(EXE_FILE) + # Use 'VERBOSE=1' to echo all commands, for example 'make help VERBOSE=1'. ifdef VERBOSE Q := @@ -93,7 +76,7 @@ endif all: $(DEFAULT) help: - $(Q)echo "--- rust-empty (0.6 003)" + $(Q)echo "--- rust-empty (0.7 000)" $(Q)echo "make run - Runs executable" $(Q)echo "make exe - Builds main executable" $(Q)echo "make lib - Both static and dynamic library" @@ -108,8 +91,6 @@ help: $(Q)echo "make doc - Builds documentation for library" $(Q)echo "make git-ignore - Setup files to be ignored by Git" $(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 - Setup executable package" $(Q)echo "make cargo-lib - Setup library package" $(Q)echo "make rust-ci-lib - Setup Travis CI Rust library" @@ -132,8 +113,6 @@ help: bench-external \ cargo-lib \ cargo-exe \ - cargo-lite-lib \ - cargo-lite-exe \ clean \ clear-git \ clear-project \ @@ -178,30 +157,6 @@ nightly-uninstall: fi \ ) -cargo-lite-exe: $(EXE_ENTRY_FILE) - $(Q)( \ - test -e cargo-lite.conf \ - && echo "--- The file 'cargo-lite.conf' already exists" \ - ) \ - || \ - ( \ - echo -e "deps = [\n]\n\n[build]\ncrate_root = \"$(EXE_ENTRY_FILE)\"\nrustc_args = []\n" > cargo-lite.conf \ - && echo "--- Created 'cargo-lite.conf' for executable" \ - && cat cargo-lite.conf \ - ) - -cargo-lite-lib: $(LIB_ENTRY_FILE) - $(Q)( \ - test -e cargo-lite.conf \ - && echo "--- The file 'cargo-lite.conf' already exists" \ - ) \ - || \ - ( \ - echo -e "deps = [\n]\n\n[build]\ncrate_root = \"$(LIB_ENTRY_FILE)\"\ncrate_type = \"library\"\nrustc_args = []\n" > cargo-lite.conf \ - && echo "--- Created 'cargo-lite.conf' for library" \ - && cat cargo-lite.conf \ - ) - cargo-exe: $(EXE_ENTRY_FILE) $(Q)( \ test -e Cargo.toml \ @@ -226,7 +181,7 @@ cargo-lib: $(LIB_ENTRY_FILE) name=$${PWD##/*/} ; \ readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \ echo -e "[package]\n\nname = \"$$name\"\nversion = \"0.0.0\"\n$$readme\nauthors = [\"Your Name \"]\ntags = []\n\n[[lib]]\n\nname = \"$$name\"\npath = \"$(LIB_ENTRY_FILE)\"\n" > Cargo.toml \ - && echo "--- Created 'Cargo.toml' for executable" \ + && echo "--- Created 'Cargo.toml' for library" \ && cat Cargo.toml \ ) @@ -260,14 +215,14 @@ doc: $(SOURCE_FILES) | src/ run: exe $(Q)cd bin/ \ - && ./main + && ./$(EXE_FILE) target-dir: $(TARGET_LIB_DIR) -exe: bin/main | $(TARGET_LIB_DIR) +exe: $(EXE) | $(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_LIB_DIR)" -L "target" \ +$(EXE): $(SOURCE_FILES) | bin/ $(EXE_ENTRY_FILE) + $(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) $(EXE_ENTRY_FILE) -o $(EXE) -L "$(TARGET_LIB_DIR)" -L "target" \ && echo "--- Built executable" \ && echo "--- Type 'make run' to run executable" @@ -342,7 +297,7 @@ git-ignore: ) \ || \ ( \ - 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\nwatch.sh\n/examples/**\n!/examples/*.rs\n!/examples/assets/" > .gitignore \ + echo -e ".DS_Store\n*~\n*#\n*.o\n*.so\n*.swp\n*.old\n*.bak\n*.kate-swp\n*.dylib\n*.dSYM\n*.dll\n*.rlib\n*.dummy\n*.exe\n*-test\n/$(EXE)\n/bin/test-internal\n/bin/test-external\n/doc/\n/target/\n/build/\n/.rust/\nrusti.sh\nwatch.sh\n/examples/**\n!/examples/*.rs\n!/examples/assets/" > .gitignore \ && echo "--- Created '.gitignore' for git" \ && cat .gitignore \ ) @@ -371,21 +326,21 @@ $(LIB_ENTRY_FILE): | src/ $(Q)test -e $(LIB_ENTRY_FILE) \ || \ ( \ - echo -e "#![crate_id = \"\"]\n#![deny(missing_doc)]\n\n//! Documentation goes here.\n" > $(LIB_ENTRY_FILE) \ + name=$${PWD##/*/} ; \ + echo -e "#![crate_name = \"$$name\"]\n#![deny(missing_doc)]\n\n//! Documentation goes here.\n" > $(LIB_ENTRY_FILE) \ ) clean: $(Q)rm -f "$(RLIB)" $(Q)rm -f "$(DYLIB)" $(Q)rm -rf "doc/" - $(Q)rm -f "bin/main" + $(Q)rm -f "$(EXE)" $(Q)rm -f "bin/test-internal" $(Q)rm -f "bin/test-external" $(Q)echo "--- Deleted binaries and documentation" clear-project: $(Q)rm -f ".symlink-info" - $(Q)rm -f "cargo-lite.conf" $(Q)rm -f "Cargo.toml" $(Q)rm -f ".travis.yml" $(Q)rm -f "rusti.sh" @@ -610,6 +565,8 @@ function build_deps { # Visit the symlinks and build the dependencies build_deps + + echo "--- Building $$current_git_dir" \ # First check for a 'build.sh' script with default settings. # Check for additional 'rust-empty.mk' file. \ @@ -627,10 +584,19 @@ function build_deps { ) \ || \ ( \ - echo "--- Building $$current_git_dir" \ + test -e Makefile \ && $$MAKE clean \ && $$MAKE \ - ) + ) \ + || \ + ( \ + test -e Cargo.toml \ + && cargo build \ + ) \ + || \ + ( \ + echo "--- ERROR: Missing Makefile in $$current_git_dir" \ + ) done cd $$current } From 5e1aa81429f26e479188ca21fe15a51d00896ee7 Mon Sep 17 00:00:00 2001 From: Sven Nilsen Date: Sun, 20 Jul 2014 20:15:50 +0200 Subject: [PATCH 2/2] Upgrade to latest Rust --- src/sdl2/event.rs | 4 ++-- src/sdl2/keyboard.rs | 2 +- src/sdl2/timer.rs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sdl2/event.rs b/src/sdl2/event.rs index 4bf9dc2f..e463dfe9 100644 --- a/src/sdl2/event.rs +++ b/src/sdl2/event.rs @@ -787,7 +787,7 @@ impl Event { Ok(window) => window, }; - let text = str::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::>().as_slice()).into_string(); + let text = String::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::>().as_slice()).into_string(); TextEditingEvent(event.timestamp as uint, window, text, event.start as int, event.length as int) } @@ -800,7 +800,7 @@ impl Event { Ok(window) => window, }; - let text = str::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::>().as_slice()).into_string(); + let text = String::from_utf8_lossy(event.text.iter().take_while(|&b| (*b) != 0i8).map(|&b| b as u8).collect::>().as_slice()).into_string(); TextInputEvent(event.timestamp as uint, window, text) } diff --git a/src/sdl2/keyboard.rs b/src/sdl2/keyboard.rs index b387afcb..82f98201 100644 --- a/src/sdl2/keyboard.rs +++ b/src/sdl2/keyboard.rs @@ -85,7 +85,7 @@ pub fn get_keyboard_state() -> HashMap { let mut current = 0; while current < raw.len() { state.insert(FromPrimitive::from_int(current as int).unwrap(), - *raw.get(current) == 1); + raw[current] == 1); current += 1; } diff --git a/src/sdl2/timer.rs b/src/sdl2/timer.rs index 50a66e41..3bd7a7ce 100644 --- a/src/sdl2/timer.rs +++ b/src/sdl2/timer.rs @@ -70,6 +70,7 @@ impl<'a> Timer<'a> { } } +#[unsafe_destructor] impl<'a> Drop for Timer<'a> { fn drop(&mut self) { if self.remove_on_drop {