-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure for an Error type, config options, and CLI args
- Loading branch information
Showing
8 changed files
with
241 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
language: rust | ||
|
||
dist: trusty | ||
|
||
os: | ||
- linux | ||
- osx | ||
|
||
addons: | ||
apt: | ||
sources: | ||
# Provides newer gcc. | ||
- ubuntu-toolchain-r-test | ||
# Provides libclang 3.9. | ||
- llvm-toolchain-trusty-3.9 | ||
packages: | ||
- autoconf2.13 | ||
# bindgen requires libclang >= 3.9. | ||
- clang-3.9 | ||
# SpiderMonkey needs gcc >= 4.9 and 5 is ICEing. | ||
- gcc-6 | ||
- g++-6 | ||
|
||
rust: | ||
- stable | ||
- beta | ||
- nightly | ||
|
||
cache: cargo | ||
|
||
env: | ||
matrix: | ||
- PROFILE="--release" | ||
- PROFILE="" | ||
- PROFILE="--release" FEATURES="" | ||
- PROFILE="" FEATURES="" | ||
- PROFILE="--release" FEATURES="--features debugmozjs" | ||
- PROFILE="" FEATURES="--features debugmozjs" | ||
|
||
before_install: | ||
- source ./ci/before_install.sh | ||
|
||
script: | ||
- cargo build $PROFILE --verbose | ||
- cargo test $PROFILE --verbose | ||
- if [[ "$PROFILE" == "--release" ]]; then | ||
cargo bench; | ||
fi | ||
- ccache -z | ||
- PROFILE="$PROFILE" FEATURES="$FEATURES" travis_wait ./ci/script.sh | ||
- ccache --show-stats |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
[package] | ||
authors = ["Nick Fitzgerald <[email protected]>"] | ||
authors = ["The Starling Project Developers"] | ||
description = "The project that will henceforth be known as `starling`." | ||
name = "starling" | ||
version = "0.1.0" | ||
|
||
[[bin]] | ||
doc = false | ||
name = "starling" | ||
path = "src/bin/starling.rs" | ||
doc = false | ||
required-features = ["clap"] | ||
|
||
[dependencies] | ||
error-chain = "0.10.0" | ||
futures = "0.1.13" | ||
tokio-core = "0.1.6" | ||
|
||
[dependencies.clap] | ||
optional = true | ||
version = "2.26.0" | ||
|
||
[dependencies.backtrace] | ||
features = ["cpp_demangle"] | ||
version = "0.3.2" | ||
|
||
[dependencies.js] | ||
git = "https://github.com/fitzgen/mozjs" | ||
branch = "smup" | ||
git = "https://github.com/fitzgen/mozjs" | ||
|
||
[features] | ||
default = ["clap"] | ||
debugmozjs = ['js/debugmozjs'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# We always want backtraces for everything. | ||
export RUST_BACKTRACE=1 | ||
|
||
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then | ||
brew install [email protected] ccache [email protected] yasm | ||
export LIBCLANG_PATH=$(find /usr/local/Cellar/llvm -type f -name libclang.dylib | head -n 1) | ||
export LIBCLANG_PATH=$(dirname $LIBCLANG_PATH) | ||
elif [[ "$TRAVIS_OS_NAME" == "linux" ]]; then | ||
export CC=clang-3.9 | ||
export CXX=clang++-3.9 | ||
export LIBCLANG_PATH=/usr/lib/llvm-3.9/lib | ||
else | ||
echo "Error: unknown \$TRAVIS_OS_NAME: $TRAVIS_OS_NAME" | ||
exit 1 | ||
fi | ||
|
||
ccache -c | ||
export CCACHE=$(which ccache) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eux | ||
|
||
cargo build -v $PROFILE $FEATURES | ||
cargo test -v $PROFILE $FEATURES | ||
|
||
if [[ "$PROFILE" == "--release" && "$FEATURES" == "" ]]; then | ||
cargo bench -v | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
reorder_imports = true | ||
reorder_imported_names = true | ||
write_mode = "Overwrite" | ||
closure_block_indent_threshold = 0 | ||
use_try_shorthand = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
extern crate clap; | ||
extern crate error_chain; | ||
extern crate starling; | ||
|
||
use clap::{App, Arg}; | ||
use error_chain::ChainedError; | ||
use std::process; | ||
|
||
/// Parse the given CLI arguments into a `starling::Options` configuration | ||
/// object. | ||
/// | ||
/// If argument parsing fails, then a usage string is printed, and the process | ||
/// is exited with 1. | ||
fn parse_cli_args() -> starling::Options { | ||
let matches = App::new(env!("CARGO_PKG_NAME")) | ||
.version(env!("CARGO_PKG_VERSION")) | ||
.author(env!("CARGO_PKG_AUTHORS")) | ||
.about(env!("CARGO_PKG_DESCRIPTION")) | ||
.arg( | ||
Arg::with_name("file") | ||
.required(true) | ||
.help("The JavaScript file to evaluate as the main task."), | ||
) | ||
.get_matches(); | ||
|
||
let opts = starling::Options::new(matches.value_of("file").unwrap()); | ||
|
||
opts | ||
} | ||
|
||
fn main() { | ||
if let Err(e) = starling::run() { | ||
println!("Error: {}", e); | ||
let opts = parse_cli_args(); | ||
if let Err(e) = opts.run() { | ||
println!("{}", e.display()); | ||
process::exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,74 @@ | ||
//! The project that will henceforth be known as `starling`. | ||
//! | ||
// `error_chain!` can recurse deeply | ||
#![recursion_limit = "1024"] | ||
#![deny(missing_docs)] | ||
#![deny(missing_debug_implementations)] | ||
#![deny(unsafe_code)] | ||
// Annoying warning emitted from the `error_chain!` macro. | ||
#![allow(unused_doc_comment)] | ||
|
||
#[macro_use] | ||
extern crate error_chain; | ||
extern crate futures; | ||
extern crate tokio_core; | ||
|
||
use futures::future; | ||
use std::io; | ||
use std::path; | ||
use tokio_core::reactor::Core; | ||
|
||
/// Run the main `starling` loop. | ||
pub fn run() -> Result<(), io::Error> { | ||
error_chain! { | ||
foreign_links { | ||
Io(::std::io::Error) | ||
/// An IO error. | ||
; | ||
} | ||
} | ||
|
||
/// Configuration options for building a `starling` event loop. | ||
/// | ||
/// ``` | ||
/// extern crate starling; | ||
/// | ||
/// # fn foo() -> starling::Result<()> { | ||
/// // Construct a new `Options` builder, providing the file containing | ||
/// // the main JavaScript task. | ||
/// starling::Options::new("path/to/main.js") | ||
/// // Finish configuring the `Options` builder and run the event | ||
/// // loop! | ||
/// .run()?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
#[derive(Clone, Debug)] | ||
pub struct Options { | ||
main: path::PathBuf, | ||
} | ||
|
||
impl Options { | ||
/// Construct a new `Options` object for configuring the `starling` event | ||
/// loop. | ||
/// | ||
/// The given `main` JavaScript file will be evaluated as the main task. | ||
pub fn new<P>(main: P) -> Options | ||
where | ||
P: Into<path::PathBuf>, | ||
{ | ||
Options { main: main.into() } | ||
} | ||
|
||
/// Finish this `Options` builder and run the `starling` event loop with its | ||
/// specified configuration. | ||
pub fn run(self) -> Result<()> { | ||
run_with_options(self) | ||
} | ||
} | ||
|
||
/// Run the main `starling` event loop with the specified options. | ||
fn run_with_options(_opts: Options) -> Result<()> { | ||
let mut core = Core::new()?; | ||
core.run(future::ok(())) | ||
} | ||
|
||
#[test] | ||
fn it_works() { | ||
} | ||
fn it_works() {} |