Upgraded to latest Rust + Cargo + Rust-Empty

This commit is contained in:
Sven Nilsen 2014-06-28 13:10:47 +02:00
parent 847a52a19a
commit 83ea9ca6b4
4 changed files with 410 additions and 77 deletions

30
Cargo.toml Normal file
View file

@ -0,0 +1,30 @@
[package]
name = "rust-2048"
version = "0.0.0"
readme = "README.md"
authors = ["coeuvre <coeuvre@gmail.com>"]
tags = []
[[bin]]
name = "rust-2048"
path = "src/main.rs"
[dependencies.graphics]
git = "https://github.com/pistondevelopers/rust-graphics"
[dependencies.piston]
git = "https://github.com/pistondevelopers/piston/"
[dependencies.opengl_graphics]
git = "https://github.com/pistondevelopers/opengl_graphics"
[dependencies.sdl2_game_window]
git = "https://github.com/pistondevelopers/sdl2_game_window"

368
Makefile
View file

@ -27,6 +27,13 @@ SHELL := /bin/bash
# The default make command. # The default make command.
# Change this to 'lib' if you are building a library. # Change this to 'lib' if you are building a library.
DEFAULT = exe DEFAULT = exe
# The entry file of library source.
# Change this to support multi-crate source structure.
# For advanced usage, you can rename the file 'rust-empty.mk'
# and call it with 'make -f rust-empty.mk <command>' from your Makefile.
LIB_ENTRY_FILE = src/lib.rs
# The entry file of executable source.
EXE_ENTRY_FILE = src/main.rs
EXAMPLE_FILES = examples/*.rs EXAMPLE_FILES = examples/*.rs
SOURCE_FILES = $(shell test -e src/ && find src -type f) SOURCE_FILES = $(shell test -e src/ && find src -type f)
@ -34,28 +41,29 @@ SOURCE_FILES = $(shell test -e src/ && find src -type f)
COMPILER = rustc COMPILER = rustc
# For release: # For release:
# COMPILER_FLAGS = -O COMPILER_FLAGS = -O
# For debugging: # For debugging:
COMPILER_FLAGS = -g # COMPILER_FLAGS = -g
RUSTDOC = rustdoc RUSTDOC = rustdoc
# Extracts target from rustc. # Extracts target from rustc.
TARGET = $(shell rustc --version | 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-unknown-linux-gnu
# TARGET = x86_64-apple-darwin # 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. # 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. # The dummy file name is used to trigger the creation of the source first time.
# Next time 'rustc' will return the right file name. # Next time 'rustc' will return the right file name.
RLIB_FILE = $(shell (rustc --crate-type=rlib --crate-file-name "src/lib.rs" 2> /dev/null) || (echo "dummy.rlib")) 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. # 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 "src/lib.rs" 2> /dev/null) || (echo "dummy.dylib")) 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 ifdef VERBOSE
Q := Q :=
else else
@ -65,35 +73,38 @@ endif
all: $(DEFAULT) all: $(DEFAULT)
help: help:
$(Q)echo "--- rust-empty (0.3 005)" \ $(Q)echo "--- rust-empty (0.6 003)"
&& echo "make run - Runs executable" \ $(Q)echo "make run - Runs executable"
&& echo "make exe - Builds main executable" \ $(Q)echo "make exe - Builds main executable"
&& echo "make lib - Both static and dynamic library" \ $(Q)echo "make lib - Both static and dynamic library"
&& echo "make rlib - Static library" \ $(Q)echo "make rlib - Static library"
&& echo "make dylib - Dynamic library" \ $(Q)echo "make dylib - Dynamic library"
&& echo "make test - Tests library internally and externally" \ $(Q)echo "make test - Tests library internally and externally"
&& echo "make test-internal - Tests library internally" \ $(Q)echo "make test-internal - Tests library internally"
&& echo "make test-external - Tests library externally" \ $(Q)echo "make test-external - Tests library externally"
&& echo "make bench - Benchmarks library internally and externally" \ $(Q)echo "make bench - Benchmarks library internally and externally"
&& echo "make bench-internal - Benchmarks library internally" \ $(Q)echo "make bench-internal - Benchmarks library internally"
&& echo "make bench-external - Benchmarks library externally" \ $(Q)echo "make bench-external - Benchmarks library externally"
&& echo "make doc - Builds documentation for library" \ $(Q)echo "make doc - Builds documentation for library"
&& echo "make git-ignore - Setup files to be ignored by Git" \ $(Q)echo "make git-ignore - Setup files to be ignored by Git"
&& echo "make examples - Builds examples" \ $(Q)echo "make examples - Builds examples"
&& echo "make cargo-lite-exe - Setup executable package" \ $(Q)echo "make cargo-lite-exe - Setup executable package"
&& echo "make cargo-lite-lib - Setup library package" \ $(Q)echo "make cargo-lite-lib - Setup library package"
&& echo "make cargo-exe - EXPERIMENTAL: Setup executable package" \ $(Q)echo "make cargo-exe - Setup executable package"
&& echo "make cargo-lib - EXPERIMENTAL: Setup library package" \ $(Q)echo "make cargo-lib - Setup library package"
&& echo "make rust-ci-lib - Setup Travis CI Rust library" \ $(Q)echo "make rust-ci-lib - Setup Travis CI Rust library"
&& echo "make rust-ci-exe - Setup Travis CI Rust executable" \ $(Q)echo "make rust-ci-exe - Setup Travis CI Rust executable"
&& echo "make rusti - Setup 'rusti.sh' for interactive Rust" \ $(Q)echo "make rusti - Setup 'rusti.sh' for interactive Rust"
&& echo "make loc - Count lines of code in src folder" \ $(Q)echo "make watch - Setup 'watch.sh' for compilation on save"
&& echo "make nightly-install - Installs Rust nightly built" \ $(Q)echo "make loc - Count lines of code in src folder"
&& echo "make nightly-uninstall - Uninstalls Rust nightly built" \ $(Q)echo "make nightly-install - Installs Rust nightly build"
&& echo "make clean - Deletes binaries and documentation." \ $(Q)echo "make nightly-uninstall - Uninstalls Rust nightly build"
&& echo "make clear-project - WARNING: Deletes project files except 'Makefile'" \ $(Q)echo "make clean - Deletes binaries and documentation."
&& echo "make clear-git - WARNING: Deletes Git setup" \ $(Q)echo "make clear-project - WARNING: Deletes project files except 'Makefile'"
&& echo "make symlink-info - Symlinked libraries dependency info" $(Q)echo "make clear-git - WARNING: Deletes Git setup"
$(Q)echo "make symlink-build - Creates a script for building dependencies"
$(Q)echo "make symlink-info - Symlinked libraries dependency info"
$(Q)echo "make target-dir - Creates directory for current target"
.PHONY: \ .PHONY: \
bench \ bench \
@ -113,10 +124,13 @@ help:
rusti \ rusti \
rust-ci-lib \ rust-ci-lib \
rust-ci-exe \ rust-ci-exe \
symlink-build \
symlink-info \ symlink-info \
target-dir \
test \ test \
test-internal \ test-internal \
test-external test-external \
watch
nightly-install: nightly-install:
$(Q)cd ~ \ $(Q)cd ~ \
@ -144,31 +158,31 @@ nightly-uninstall:
fi \ fi \
) )
cargo-lite-exe: src/main.rs cargo-lite-exe: $(EXE_ENTRY_FILE)
$(Q)( \ $(Q)( \
test -e cargo-lite.conf \ test -e cargo-lite.conf \
&& echo "--- The file 'cargo-lite.conf' already exists" \ && 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 \ 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" \ && echo "--- Created 'cargo-lite.conf' for executable" \
&& cat cargo-lite.conf \ && cat cargo-lite.conf \
) )
cargo-lite-lib: src/lib.rs cargo-lite-lib: $(LIB_ENTRY_FILE)
$(Q)( \ $(Q)( \
test -e cargo-lite.conf \ test -e cargo-lite.conf \
&& echo "--- The file 'cargo-lite.conf' already exists" \ && 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 \ 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" \ && echo "--- Created 'cargo-lite.conf' for library" \
&& cat cargo-lite.conf \ && cat cargo-lite.conf \
) )
cargo-exe: src/main.rs cargo-exe: $(EXE_ENTRY_FILE)
$(Q)( \ $(Q)( \
test -e Cargo.toml \ test -e Cargo.toml \
&& echo "--- The file 'Cargo.toml' already exists" \ && echo "--- The file 'Cargo.toml' already exists" \
@ -177,12 +191,12 @@ cargo-exe: src/main.rs
( \ ( \
name=$${PWD##/*/} ; \ name=$${PWD##/*/} ; \
readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \ 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 \ 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" \ && echo "--- Created 'Cargo.toml' for executable" \
&& cat Cargo.toml \ && cat Cargo.toml \
) )
cargo-lib: src/main.rs cargo-lib: $(LIB_ENTRY_FILE)
$(Q)( \ $(Q)( \
test -e Cargo.toml \ test -e Cargo.toml \
&& echo "--- The file 'Cargo.toml' already exists" \ && echo "--- The file 'Cargo.toml' already exists" \
@ -191,47 +205,49 @@ cargo-lib: src/main.rs
( \ ( \
name=$${PWD##/*/} ; \ name=$${PWD##/*/} ; \
readme=$$((test -e README.md && echo -e "readme = \"README.md\"") || ("")) ; \ 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 \ 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" \ && echo "--- Created 'Cargo.toml' for executable" \
&& cat Cargo.toml \ && cat Cargo.toml \
) )
rust-ci-lib: src/lib.rs rust-ci-lib: $(LIB_ENTRY_FILE)
$(Q)( \ $(Q)( \
test -e .travis.yml \ test -e .travis.yml \
&& echo "--- The file '.travis.yml' already exists" \ && 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 \ echo -e "install:\n - wget http://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz -O - | sudo tar zxf - --strip-components 1 -C /usr/local\nscript:\n - make lib\n" > .travis.yml \
&& echo "--- Created '.travis.yml' for library" \ && echo "--- Created '.travis.yml' for library" \
&& cat .travis.yml \ && cat .travis.yml \
) )
rust-ci-exe: src/main.rs rust-ci-exe: $(EXE_ENTRY_FILE)
$(Q)( \ $(Q)( \
test -e .travis.yml \ test -e .travis.yml \
&& echo "--- The file '.travis.yml' already exists" \ && 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 \ echo -e "install:\n - wget http://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz -O - | sudo tar zxf - --strip-components 1 -C /usr/local\nscript:\n - make exe\n" > .travis.yml \
&& echo "--- Created '.travis.yml' for executable" \ && echo "--- Created '.travis.yml' for executable" \
&& cat .travis.yml \ && cat .travis.yml \
) )
doc: $(SOURCE_FILES) | src/ doc: $(SOURCE_FILES) | src/
$(Q)$(RUSTDOC) src/lib.rs -L "target/$(TARGET)/lib" \ $(Q)$(RUSTDOC) $(LIB_ENTRY_FILE) -L "$(TARGET_LIB_DIR)" \
&& echo "--- Built documentation" && echo "--- Built documentation"
run: exe run: exe
$(Q)cd bin/ \ $(Q)cd bin/ \
&& ./main && ./main
target-dir: $(TARGET_LIB_DIR)
exe: bin/main | $(TARGET_LIB_DIR) exe: bin/main | $(TARGET_LIB_DIR)
bin/main: $(SOURCE_FILES) | bin/ src/main.rs bin/main: $(SOURCE_FILES) | bin/ $(EXE_ENTRY_FILE)
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) src/main.rs -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 "--- Built executable" \
&& echo "--- Type 'make run' to run executable" && echo "--- Type 'make run' to run executable"
@ -244,7 +260,7 @@ test-external: bin/test-external
&& ./test-external && ./test-external
bin/test-external: $(SOURCE_FILES) | rlib bin/ src/test.rs 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" && echo "--- Built external test runner"
test-internal: bin/test-internal test-internal: bin/test-internal
@ -252,7 +268,7 @@ test-internal: bin/test-internal
&& ./test-internal && ./test-internal
bin/test-internal: $(SOURCE_FILES) | rlib src/ bin/ bin/test-internal: $(SOURCE_FILES) | rlib src/ bin/
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --test src/lib.rs -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" && echo "--- Built internal test runner"
bench: bench-internal bench-external bench: bench-internal bench-external
@ -268,23 +284,23 @@ lib: rlib dylib
rlib: $(RLIB) rlib: $(RLIB)
$(RLIB): $(SOURCE_FILES) | src/lib.rs $(TARGET_LIB_DIR) $(RLIB): $(SOURCE_FILES) | $(LIB_ENTRY_FILE) $(TARGET_LIB_DIR)
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=rlib src/lib.rs -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" && echo "--- Built rlib"
dylib: $(DYLIB) dylib: $(DYLIB)
$(DYLIB): $(SOURCE_FILES) | src/lib.rs $(TARGET_LIB_DIR) $(DYLIB): $(SOURCE_FILES) | $(LIB_ENTRY_FILE) $(TARGET_LIB_DIR)
$(Q)$(COMPILER) --target "$(TARGET)" $(COMPILER_FLAGS) --crate-type=dylib src/lib.rs -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" && echo "--- Built dylib"
bin: bin/:
$(Q)mkdir -p bin $(Q)mkdir -p bin
$(TARGET_LIB_DIR): $(TARGET_LIB_DIR):
$(Q)mkdir -p $(TARGET_LIB_DIR) $(Q)mkdir -p $(TARGET_LIB_DIR)
src: src/:
$(Q)mkdir -p src $(Q)mkdir -p src
examples-dir: examples-dir:
@ -306,7 +322,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\n" > .gitignore \ 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 "--- Created '.gitignore' for git" \ && echo "--- Created '.gitignore' for git" \
&& cat .gitignore \ && cat .gitignore \
) )
@ -314,14 +330,14 @@ git-ignore:
examples: $(EXAMPLE_FILES) examples: $(EXAMPLE_FILES)
$(EXAMPLE_FILES): lib examples-dir $(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 examples" && echo "--- Built '$@' (make $@)"
src/main.rs: | src/ $(EXE_ENTRY_FILE): | src/
$(Q)test -e src/main.rs \ $(Q)test -e $(EXE_ENTRY_FILE) \
|| \ || \
( \ ( \
echo -e "fn main() {\n\tprintln!(\"Hello world!\");\n}" > src/main.rs \ echo -e "fn main() {\n\tprintln!(\"Hello world!\");\n}" > $(EXE_ENTRY_FILE) \
) )
src/test.rs: | src/ src/test.rs: | src/
@ -331,11 +347,11 @@ src/test.rs: | src/
touch src/test.rs \ touch src/test.rs \
) )
src/lib.rs: | src/ $(LIB_ENTRY_FILE): | src/
$(Q)test -e src/lib.rs \ $(Q)test -e $(LIB_ENTRY_FILE) \
|| \ || \
( \ ( \
echo -e "#![crate_id = \"\"]\n#![deny(missing_doc)]\n\n//! Documentation goes here.\n" > src/lib.rs \ echo -e "#![crate_id = \"\"]\n#![deny(missing_doc)]\n\n//! Documentation goes here.\n" > $(LIB_ENTRY_FILE) \
) )
clean: clean:
@ -350,8 +366,10 @@ clean:
clear-project: clear-project:
$(Q)rm -f ".symlink-info" $(Q)rm -f ".symlink-info"
$(Q)rm -f "cargo-lite.conf" $(Q)rm -f "cargo-lite.conf"
$(Q)rm -f "Cargo.toml"
$(Q)rm -f ".travis.yml" $(Q)rm -f ".travis.yml"
$(Q)rm -f "rusti.sh" $(Q)rm -f "rusti.sh"
$(Q)rm -f "watch.sh"
$(Q)rm -rf "target/" $(Q)rm -rf "target/"
$(Q)rm -rf "src/" $(Q)rm -rf "src/"
$(Q)rm -rf "bin/" $(Q)rm -rf "bin/"
@ -378,7 +396,7 @@ while true; do
echo -n "> " echo -n "> "
read line read line
TMP="`mktemp r.XXXXXX`" 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)] #![feature(globs, macro_rules, phase, struct_variant)]
extern crate arena; extern crate arena;
extern crate collections; extern crate collections;
@ -392,6 +410,8 @@ while true; do
extern crate native; extern crate native;
extern crate num; extern crate num;
extern crate rand; extern crate rand;
extern crate regex;
#[phase(syntax)] extern crate regex_macros;
extern crate rustc; extern crate rustc;
extern crate rustdoc; extern crate rustdoc;
extern crate rustuv; extern crate rustuv;
@ -430,6 +450,206 @@ rusti: $(TARGET_LIB_DIR)
&& echo "--- Type './rusti.sh' to start interactive Rust" \ && echo "--- Type './rusti.sh' to start interactive Rust" \
) )
# borrowed from http://stackoverflow.com/q/649246/1256624
define WATCH_SCRIPT
#!/bin/bash
#written by zzmp
# This script will recompile a rust project using `make`
# every time something in the specified directory changes.
# Watch files in infinite loop
watch () {
UNAME=$$(uname)
if [ -e "$$2" ]; then
echo "Watching files in $$2.."
CTIME=$$(date "+%s")
while :; do
sleep 1
for f in `find $$2 -type f -name "*.rs"`; do
if [[ $$UNAME == "Darwin" ]]; then
st_mtime=$$(stat -f "%m" "$$f")
elif [[ $$UNAME == "FreeBSD" ]]; then
st_mtime=$$(stat -f "%m" "$$f")
else
st_mtime=$$(stat -c "%Y" "$$f")
fi
if [ $$st_mtime -gt $$CTIME ]; then
CTIME=$$(date "+%s")
echo "~~~ Rebuilding"
$$1
if [ ! $$? -eq 0 ]; then
echo ""
fi
fi
done
done
else
echo "$$2 is not a valid directory"
fi
}
# Capture user input with defaults
CMD=$${1:-make}
DIR=$${2:-src}
if [ $${CMD:0:2} = '-h' ]; then
echo '
This script will recompile a rust project using `make`
every time something in the specified directory changes.
Use: ./watch.sh [CMD] [DIR]
Example: ./watch.sh "make run" src
CMD: Command to execute
Complex commands may be passed as strings
`make` by default
DIR: Directory to watch
src by default
If DIR is supplied, CMD must be as well.\n'
else
watch "$$CMD" "$$DIR"
fi
endef
export WATCH_SCRIPT
watch: $(TARGET_LIB_DIR)
$(Q)( \
test -e watch.sh \
&& echo "--- The file 'watch.sh' already exists" \
) \
|| \
( \
echo -e "$$WATCH_SCRIPT" > watch.sh \
&& chmod +x watch.sh \
&& echo "--- Created 'watch.sh'" \
&& echo "--- Type './watch.sh' to start compilation on save" \
&& echo "--- Type './watch.sh -h' for more options" \
)
# borrowed from http://stackoverflow.com/q/649246/1256624
define SYMLINK_BUILD_SCRIPT
#!/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_LIB_DIR) -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"
)
endef
export SYMLINK_BUILD_SCRIPT
symlink-build:
$(Q)( \
test -e build.sh \
&& echo "--- The file 'build.sh' already exists" \
) \
|| \
( \
echo -e "$$SYMLINK_BUILD_SCRIPT" > build.sh \
&& chmod +x build.sh \
&& echo "--- Created 'build.sh'" \
&& echo "--- Type './build.sh deps' to build everything" \
)
loc: loc:
$(Q)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 && find src/ -type f -name "*.rs" -exec cat {} \; | wc -l
@ -438,7 +658,7 @@ loc:
# prints the commit hash with remote branches containing that commit. # prints the commit hash with remote branches containing that commit.
symlink-info: symlink-info:
$(Q) current=$$(pwd) ; \ $(Q) current=$$(pwd) ; \
for symlib in $$(find target/*/lib -type l) ; do \ for symlib in $$(find $(TARGET_LIB_DIR) -type l) ; do \
cd $$current ; \ cd $$current ; \
echo $$symlib ; \ echo $$symlib ; \
original_file=$$(readlink $$symlib) ; \ original_file=$$(readlink $$symlib) ; \
@ -446,7 +666,11 @@ symlink-info:
cd $$original_dir ; \ cd $$original_dir ; \
commit=$$(git rev-parse HEAD) ; \ commit=$$(git rev-parse HEAD) ; \
echo $$commit ; \ echo $$commit ; \
echo "origin:" ; \
git config --get remote.origin.url ; \ git config --get remote.origin.url ; \
echo "upstream:" ; \
git config --get remote.upstream.url ; \
echo "available in remote branches:" ; \
git branch -r --contains $$commit ; \ git branch -r --contains $$commit ; \
echo "" ; \ echo "" ; \
done \ done \

78
build.sh Executable file
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"
)

View file

@ -18,6 +18,7 @@ pub struct App<'a> {
logo: Option<Texture>, logo: Option<Texture>,
comment1: Option<Texture>, comment1: Option<Texture>,
comment2: Option<Texture>, comment2: Option<Texture>,
window_background_color: [f32, ..4],
gl: Gl, gl: Gl,
} }
@ -32,6 +33,7 @@ impl<'a> App<'a> {
logo: None, logo: None,
comment1: None, comment1: None,
comment2: None, comment2: None,
window_background_color: [1.0, 1.0, 1.0, 1.0],
gl: Gl::new(), gl: Gl::new(),
} }
@ -90,17 +92,16 @@ impl<'a> Game for App<'a> {
self.comment2 = Some(Texture::from_path(&asset_store.path("comment2.png").unwrap()).unwrap()); self.comment2 = Some(Texture::from_path(&asset_store.path("comment2.png").unwrap()).unwrap());
} }
fn render(&mut self, args: &mut RenderArgs) { fn render(&mut self, args: &RenderArgs) {
self.gl.viewport(0, 0, args.width as i32, args.height as i32);
let ref c = Context::abs(args.width as f64, args.height as f64); let ref c = Context::abs(args.width as f64, args.height as f64);
c.color(self.window_background_color).draw(&mut self.gl);
let bg = c.rgba(self.settings.window_background_color[0], self.settings.window_background_color[1], self.settings.window_background_color[2], 1.0);
bg.draw(&mut self.gl);
self.render_ui(c); self.render_ui(c);
self.board.render(self.number_renderer.get_ref(), c, &mut self.gl); self.board.render(self.number_renderer.get_ref(), c, &mut self.gl);
} }
fn update(&mut self, args: &mut UpdateArgs) { fn update(&mut self, args: &UpdateArgs) {
self.board.update(args.dt); self.board.update(args.dt);
} }