Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 100ec46

Browse files
committed
Merge pull request #51 from tomassedovic/build-script
Convert to the supported Cargo build script This should make it more consistent to build & use the native libtcod bindings for everyone. We've moved from the old anything-goes build scripts to the new ones that only allow Rust code. Based on the conventions in the build-script guide[1], this introduces a new crate called `tcod-sys`. That crate defines all the function signatures and type definitions in `libtcod` and so replaces what was previously in `tcod-rs/src/ffi.rs`. It also bundles a libtcod snapshot source known to work (the latest checkout of the `1.5.x` branch) plus fixes to make it compile on Mac OS X. And a build script that knows how to build it and where to put the artifacts. This should hopefully make building tcod-rs more repeatable for everyone. This is a breaking change. To migrate, just make sure you have the right dependencies to build libtcod installed (see readme) and remove any `build = ...` section from your game's `Cargo.toml`. When you run `cargo build`, libtcod will be built as part that build process. If you want to avoid building libtcod and provide your own pre-built `libtcod.{so,dll,dylib}`, you can use Cargo's build override mechanism[2]. See `tcod-rs/.cargo/config` for an example. You probably want to put the `.cargo/config` file in the root of your game, but it can be in any directory above that, too (such as your `$HOME`). I have tested this on my 64bit Linux Mint 17 machine and a 32bit Windows 7 box with MinGW. @pmsanford tested this on OSX. [1]: http://doc.crates.io/build-script.html [2]: http://doc.crates.io/build-script.html#overriding-build-scripts Closes #32.
2 parents bfe497d + 98ca154 commit 100ec46

File tree

290 files changed

+90028
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+90028
-96
lines changed

.cargo/config

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Using binary distribution of libtcod instead of building it from source:
2+
# For more info, read: http://doc.crates.io/build-script.html and http://doc.crates.io/config.html
3+
#
4+
# In general, you download your the compiled libraries (libtcod.so/dll/ and
5+
# libtcodgui.so/dll), put them into `precompiled/$target` and uncomment the
6+
# corresponding section below.
7+
8+
9+
# 64-bit Linux:
10+
#
11+
# Download this: http://roguecentral.org/doryen/?file_id=28
12+
# Copy libtcod.so and libtcodgui.so to: precompiled/x86_64-unknown-linux-gnu
13+
# You may also need to create libtcod.so.1 and libtcodgui.so.1 because reasons?
14+
# Uncomment this section:
15+
#
16+
# [target.x86_64-unknown-linux-gnu.tcod]
17+
# rustc-flags = "-L precompiled/x86_64-unknown-linux-gnu -l tcod"
18+
19+
20+
# 32-bit Linux:
21+
#
22+
# Download this: http://roguecentral.org/doryen/?file_id=26
23+
# Copy libtcod.so and libtcodgui.so to: precompiled/i686-unknown-linux-gnu
24+
# You may also need to create libtcod.so.1 and libtcodgui.so.1 because reasons?
25+
# Uncomment this section:
26+
#
27+
# [target.i686-unknown-linux-gnu.tcod]
28+
# rustc-flags = "-L precompiled/i686-unknown-linux-gnu -l tcod"
29+
30+
31+
# Windows:
32+
#
33+
# Download this: http://roguecentral.org/doryen/?file_id=27
34+
# Copy libtcod-mingw.dll, libtcod-gui-mingw.dll and SDL.dll to: precompiled/i686-pc-windows-gnu
35+
# You must also create libtcod.dll and libtcod-gui.dll because reasons?
36+
# Uncomment this section:
37+
#
38+
# [target.i686-pc-windows-gnu.tcod]
39+
# rustc-flags = "-L precompiled/i686-pc-windows-gnu -l tcod"

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
.DS_Store
22
*~
33
*#
4+
*.a
45
*.o
56
*.so
6-
*.swp
77
*.dylib
8+
*.swp
89
*.dSYM
910
*.dll
1011
*.rlib
@@ -24,3 +25,6 @@ watch.sh
2425
!/examples/*.rs
2526
!/examples/assets/
2627
/Cargo.lock
28+
/tcod-sys/target/
29+
!/tcod-sys/libtcod/SDL*.dll
30+
!/tcod-sys/libtcod/dependencies/**

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ language: rust
22
before_install:
33
- sudo apt-get update -qq
44
install:
5-
- sudo apt-get install -y libsdl1.2debian
6-
- curl -L "http://roguecentral.org/doryen/?file_id=28" -o libtcod-1.5.1-linux64.tar.gz
7-
- tar -xzf libtcod-1.5.1-linux64.tar.gz
8-
- sudo cp libtcod-1.5.1/libtcod{,gui}.so /usr/lib/x86_64-linux-gnu/
5+
- sudo apt-get install -y upx electric-fence libsdl1.2-dev
96
script:
107
- cargo build --verbose
118
- cargo test --verbose

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
name = "tcod"
33
version = "0.3.0"
44
5-
build = "./build.sh"
65

76
[lib]
8-
97
name = "tcod"
108
path = "src/lib.rs"
119

10+
[dependencies.tcod-sys]
11+
path = "tcod-sys"
1212

1313
# TODO: temporarily disabling debuginfo until this is fixed:
1414
# https://github.com/rust-lang/rust/issues/17257

README.md

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
libtcod bindings for Rust
22
-------------------------
33

4-
[libtcod a.k.a. "The Doryen Library"](http://doryen.eptalys.net/libtcod/) is a
5-
smallish library designed for writing roguelikes. It provides a bunch of useful
6-
functionality such as:
4+
[libtcod a.k.a. "The Doryen Library"](http://roguecentral.org/doryen/libtcod/)
5+
is a smallish library designed for writing roguelikes. It provides a bunch of
6+
useful functionality such as:
77

88
* Text-based graphics API that doesn't suck as much as curses or OpenGL
99
* Colours! (like, more than 16)
1010
* Keyboard and mouse input
1111
* Path finding
1212
* Field of view
1313
* Portable (works on linux and windows; mac too but requires some effort)
14-
* [lots of other stuff](http://doryen.eptalys.net/libtcod/features/)
14+
* [lots of other stuff](http://roguecentral.org/doryen/libtcod/features/)
1515

1616

1717
This project provides [Rust](http://www.rust-lang.org/) bindings for libtcod
@@ -49,7 +49,7 @@ complete however.
4949
* Most of the _Console_ features (new, init_root, blit, putting text on the
5050
screen, reading key presses, etc.)
5151
* Most of _Map_ (new, size, set, is_walkable)
52-
* Most of the A* _Path_ features (no Dijkstra yet)
52+
* A* and Dijkstra _Path_ finding
5353
* Some of the _System_ layer (get/set FPS, last frame length)
5454

5555
### Probably Won't Ever Be Implemented Because Rust Provides This Already
@@ -66,88 +66,91 @@ complete however.
6666
How to use this
6767
---------------
6868

69-
You can build this library by cloning the repository and typing `cargo build`. You need to have `libtcod` in your library path, you can
70-
download it from the [libtcod download page](http://doryen.eptalys.net/libtcod/download/), or install it using some package manager. See below for Mac OS X specific install instructions.
69+
`tcod-rs` depends on `libtcod` so you need to build or download the official
70+
version. The `libtcod` version known to work is bundled with `tcod-sys` and
71+
Cargo will build it for you, but you need the build dependencies installed.
7172

72-
This will compile and link the library and a simple example in `target`
73+
Alternatively, you can provide the precompiled libtcod library to override the
74+
building process. [See below](#using-existing-binary-distribution).
7375

74-
Other than that, look at the source and read
75-
[libtcod documentation](http://doryen.eptalys.net/data/libtcod/doc/1.5.1/index2.html?c=true&cpp=true&cs=true&py=true&lua=true).
76+
To use `tcod-rs`, add this to your game's `Cargo.toml`:
7677

77-
## OS X specific instructions
78+
[dependencies.tcod]
79+
git = "https://github.com/tomassedovic/tcod-rs.git"
7880

79-
There are two dependencies to installing on OS X:
80-
* [Homebrew](http://brew.sh/)
81-
* `mercurial`
82-
* `sdl`
83-
* `wget`
84-
* `libtcod`
8581

86-
Unfortunately, `libtcod` is no longer officially supported on Mac OS X. As of 8/20/2014 the following instructinos work:
82+
### Building on Linux
8783

88-
Start off by installing `mercurial`, `sdl` and `wget`:
84+
Run the equivalent of:
8985

90-
```sh
91-
brew install mercurial sdl wget
92-
```
86+
$ sudo apt-get install gcc g++ make upx electric-fence libsdl1.2-dev mercurial
87+
$ cd yourgame
88+
$ cargo build
89+
$ cargo run
9390

94-
Then clone the offical `libtcod` repository (it helps if you put it in a safe place, like `~/src` or something):
91+
on your distro.
9592

96-
```sh
97-
hg clone https://bitbucket.org/jice/libtcod
98-
```
93+
You can also check the [official libtcod build instructions for Linux][linux].
9994

100-
Make sure you use the supported libtcod version:
95+
linux: http://roguecentral.org/doryen/data/libtcod/doc/1.5.2/html2/compile_libtcod_linux.html?c=true
10196

102-
```sh
103-
cd libtcod
104-
hg checkout 1.5.x
105-
```
10697

107-
Then make `libtcod` with the following commands:
98+
### Building on Windows (with MinGW)
10899

109-
```sh
110-
wget https://gist.githubusercontent.com/jaredonline/daf3c5f1ea6c7ca00e29/raw/ae91b3e47bf0de5b772eff882e477d8144cfbaf8/makefile-osx > makefiles/makefile-osx
111-
wget https://dl.dropboxusercontent.com/u/169446/osx.tar.gz
112-
tar -xzvf osx.tar.gz
113-
make -f makefiles/makefile-osx
114-
```
100+
The Windows version of `libtcod` relies on MinGW and MSYS so you have to install
101+
them:
115102

116-
If this seems a bit convoluted that's because it is. I managed to find instructions [here](http://zackhovatter.com/gamedev/2013/11/26/building-libtcod-on-os-x-mavericks.html) but at the time of writing that link was broken. I grabbed a screenshot from Google Cache and put together my own packages of OS X specific materials. In step two above you're getting an OS X specific makefile and in step three you're getting some OS X specific headers.
103+
1. [Download and run MinGW][mingw]
104+
2. In the MinGW installer, mark the following sections for installation:
105+
* C compiler (gcc)
106+
* C++ compiler (g++)
107+
* MSYS Basic System
108+
3. Open the Command prompt (cmd.exe)
109+
4. Run:
117110

118-
You can test that it all worked by running
111+
cd yourgame
112+
cargo build
113+
cargo run
119114

120-
```sh
121-
./samples_c
122-
./samples_cpp
123-
```
115+
mingw: http://sourceforge.net/projects/mingw/files/
124116

125-
And you should get some pretty windows.
117+
You can also check the [official libtcod build instructions for Windows][windows].
126118

127-
### Building a project with it:
119+
windows: http://roguecentral.org/doryen/data/libtcod/doc/1.5.2/html2/compile_libtcod_mingw.html?c=true
128120

129-
Now, to get a project up and running with Cargo, add this to your `Cargo.toml` file:
130121

131-
```toml
132-
build = "sh .build.sh"
122+
### Building on Mac OS X
133123

134-
[dependencies.tcod]
135-
git = "https://github.com/tomassedovic/tcod-rs.git"
136-
```
124+
1. [Install Homebrew](http://brew.sh/)
125+
2. Run:
137126

138-
And add this file to your project root (`.build.sh`):
127+
$ brew install sdl wget
128+
$ cd yourgame
129+
$ cargo build
130+
$ cargo run
139131

140-
```sh
141-
#!/bin/sh
132+
This is based on the instructions from [Jared McFarland's roguelike tutorial][macosx].
142133

143-
export LIBTCOD_SRC_DIR="/PATH/TO/YOUR/src/libtcod"
144-
cp $LIBTCOD_SRC_DIR/*.dylib $OUT_DIR/
145-
cp $LIBTCOD_SRC_DIR/terminal.png $OUT_DIR/../../../
146-
```
134+
macosx: http://jaredonline.svbtle.com/roguelike-tutorial-in-rust-part-1
147135

148-
That copies the required `.dyblib` files from where you built `libtcod` to your project's target directory, and the `terminal.png` that `sdl` requires to your projects root directory.
136+
---
137+
138+
To test this, you can clone this repository directly and run the one of the
139+
provided examples:
140+
141+
$ git clone https://github.com/tomassedovic/tcod-rs.git
142+
$ cd tcod-rs
143+
$ cargo run --example keyboard
144+
145+
146+
### Using existing binary distribution
147+
148+
If you don't want to build libtcod yourself, you can
149+
[instruct Cargo to override the build script][override]. See `.cargo/config`
150+
from the repository for an example.
151+
152+
override: http://doc.crates.io/build-script.html#overriding-build-scripts
149153

150-
After that you should be good to go! Happy building!
151154

152155
Contributing
153156
------------
@@ -173,9 +176,14 @@ You can regenerate the raw bindings by running:
173176

174177
### Contributors
175178

176-
* Edu Garcia <[email protected]>
177-
* Jared McFarland <[email protected]>
178-
* Tomas Sedovic <[email protected]>
179+
180+
* Bastien Léonard, @bastienleonard, <[email protected]>
181+
* Edu Garcia, @Arcnor, <[email protected]>
182+
* @Moredread
183+
* Jared McFarland, @jaredonline, <[email protected]>
184+
* Paul Sanford, @pmsanford, <[email protected]>
185+
* @Pranz, <[email protected]>
186+
* Tomas Sedovic, @tomassedovic, <[email protected]>
179187

180188

181189
### License

build.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/colors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
// Uses the default foreground and background:
1414
con.put_char(40, 25, '@', BackgroundFlag::Set);
1515
// Custom foreground and background:
16-
con.put_char_ex(42, 25, '!', Color::new(240, 13, 20), Color::new(0, 0, 0));
16+
con.put_char_ex(42, 25, '!', Color{r: 240, g: 13, b: 20}, Color{r: 0, g: 0, b: 0});
1717

1818
Console::flush();
1919

precompiled/i686-pc-windows-gnu/.gitkeep

Whitespace-only changes.

precompiled/i686-unknown-linux-gnu/.gitkeep

Whitespace-only changes.

precompiled/x86_64-unknown-linux-gnu/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)