Skip to content

Commit

Permalink
Migrate repo to a Cargo workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
emwalker committed Nov 26, 2023
1 parent c81302c commit 818620e
Show file tree
Hide file tree
Showing 213 changed files with 118 additions and 1,921 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ local/
settings.db

# C API tests (ignore everything but source files)
gosub-bindings/tests/*
!gosub-bindings/tests/*.c
bindings/tests/*
!bindings/tests/*.c
*.dSYM
23 changes: 15 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 6 additions & 71 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,72 +1,7 @@
[package]
name = "gosub-engine"
version = "0.1.0"
edition = "2021"
rust-version = "1.73"
authors = ["Gosub Community <[email protected]>"]
description = "An HTML5 browser engine written in Rust."
license = "MIT"
repository = "https://github.com/gosub-browser/gosub-engine"
readme = "README.md"
keywords = ["html5", "parser", "browser", "Rust", "DOM"]
[workspace]

[[test]]
name = "tokenizer"
path = "tests/tokenizer.rs"

[[test]]
name = "tree_construction"
path = "tests/tree_construction.rs"

[[bench]]
name = "tokenizer"
harness = false

[[bench]]
name = "tree_construction"
harness = false

[[bench]]
name = "tree_iterator"
harness = false

[dependencies]
phf = { version = "0.11.2", features = ["macros"] }
derive_more = "0.99"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_derive = "1.0"
regex = "1"
lazy_static = "1.4"
typed-arena = "2.0.2"
thiserror = "1.0.50"
ureq = "2.8.0"
anyhow = "1.0.75"
uuid = { version = "1.6.0", features = ["v4"] }
colored = "2.0.4"
walkdir = "2.3"
nom = "7.1.3"
nom_locate = "4.2.0"
sqlite = "0.32.0"
wildmatch = "2.1.1"
clap = { version = "4.4.8", features = ["derive"] }
cli-table = "0.4.7"
textwrap = "0.16.0"
log = "0.4.20"
domain-lookup-tree = "0.1"
hickory-resolver = "0.24.0"
simple_logger = "4.2.0"
libc = "0.2"
shared_singleton = "0.1.0"
testing_logger = "0.1.1"
cookie = { version = "0.18.0", features = ["secure", "private"] }
http = "1.0.0"
url = "2.5.0"

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
test-case = "3.3.1"

[features]
# Enables extended debugging information during parsing.
debug_parser = []
resolver = "2"
members = [
"engine",
"bindings",
]
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test_commands:
cargo run --bin html5-parser-test >/dev/null
cargo run --bin parser-test >/dev/null
cargo run --bin config-store list >/dev/null
cargo run --example html5-parser > /dev/null

help: ## Display available commands
echo "Available make commands:"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion gosub-bindings/Cargo.toml → bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
gosub-engine = { path = "../" }
gosub-engine = { path = "../engine" }

[lib]
crate-type = ["staticlib"]
7 changes: 4 additions & 3 deletions gosub-bindings/Makefile → bindings/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ CFLAGS_DEBUG := -std=c99 -g -Wall -Wextra -O0
CFLAGS_RELEASE := -std=c99 -Wall -Wextra -O2
CFLAGS := $(CFLAGS_DEBUG)
CC := gcc
TARGET_DIR=../target/debug

LDFLAGS := -L./target/debug
LDFLAGS := -L$(TARGET_DIR)
NODE_SRC_DIR := $(SRC_DIR)/nodes
bindings: # build gosub static library to be used externally
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(SRC_DIR)/gosub_api.c $(SRC_DIR)/nodes.c $(NODE_SRC_DIR)/text.c
ar rcs libgosub.a gosub_api.o nodes.o text.o
rm *.o
test -d lib || mkdir lib
cp ./target/debug/libgosub_bindings.a lib/
cp $(TARGET_DIR)/libgosub_bindings.a lib/
cp ./libgosub.a lib/

TEST_SRC_DIR := tests
test: # build and run tests for bindings
$(CC) $(TEST_SRC_DIR)/render_tree_test.c -L./ -lgosub -L./target/debug -lgosub_bindings -lsqlite3 -lm -o $(TEST_SRC_DIR)/render_tree_test $(CPPFLAGS) $(CFLAGS)
$(CC) $(TEST_SRC_DIR)/render_tree_test.c -L./ -lgosub $(LDFLAGS) -lgosub_bindings -lsqlite3 -lm -o $(TEST_SRC_DIR)/render_tree_test $(CPPFLAGS) $(CFLAGS)
./$(TEST_SRC_DIR)/render_tree_test

format:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
[package]
name = "gosub-engine"
version = "0.1.0"
edition = "2021"
rust-version = "1.73"
authors = ["Gosub Community <[email protected]>"]
description = "An HTML5 browser engine written in Rust."
license = "MIT"
repository = "https://github.com/gosub-browser/gosub-engine"
readme = "README.md"
keywords = ["html5", "parser", "browser", "Rust", "DOM"]

[[test]]
name = "tokenizer"
path = "tests/tokenizer.rs"

[[test]]
name = "tree_construction"
path = "tests/tree_construction.rs"

[[example]]
name = "html5-parser"
path = "examples/html5-parser.rs"

[[bench]]
name = "tokenizer"
harness = false

[[bench]]
name = "tree_construction"
harness = false

[[bench]]
name = "tree_iterator"
harness = false

[dependencies]
phf = { version = "0.11.2", features = ["macros"] }
derive_more = "0.99"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_derive = "1.0"
regex = "1"
lazy_static = "1.4"
typed-arena = "2.0.2"
thiserror = "1.0.50"
ureq = "2.8.0"
anyhow = "1.0.75"
uuid = { version = "1.6.0", features = ["v4"] }
colored = "2.0.4"
walkdir = "2.3"
nom = "7.1.3"
nom_locate = "4.2.0"
sqlite = "0.32.0"
wildmatch = "2.1.1"
clap = { version = "4.4.8", features = ["derive"] }
cli-table = "0.4.7"
textwrap = "0.16.0"
log = "0.4.20"
domain-lookup-tree = "0.1"
hickory-resolver = "0.24.0"
simple_logger = "4.2.0"
libc = "0.2"
shared_singleton = "0.1.0"
testing_logger = "0.1.1"
cookie = { version = "0.18.0", features = ["secure", "private"] }
http = "1.0.0"
url = "2.5.0"

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
test-case = "3.3.1"

[features]
# Enables extended debugging information during parsing.
debug_parser = []
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use criterion::{criterion_group, criterion_main, Criterion};
use gosub_engine::testing::tree_construction;
use gosub_engine::testing::tree_construction::fixture::fixture_root_path;
use gosub_engine::testing::tree_construction::Harness;

fn criterion_benchmark(c: &mut Criterion) {
Expand All @@ -8,8 +9,9 @@ fn criterion_benchmark(c: &mut Criterion) {

// Careful about reading files inside the closure
let filenames = Some(&["tests1.dat"][..]);
let fixtures =
tree_construction::fixture::read_fixtures(filenames).expect("problem loading fixtures");
let root = fixture_root_path();
let fixtures = tree_construction::fixture::read_fixtures(root, filenames)
.expect("problem loading fixtures");

let mut harness = Harness::new();

Expand Down
4 changes: 2 additions & 2 deletions benches/tree_iterator.rs → engine/benches/tree_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn wikipedia_main_page(c: &mut Criterion) {
let mut group = c.benchmark_group("Tree Iterator");
group.significance_level(0.1).sample_size(500);

let html_file = File::open("tests/data/tree_iterator/wikipedia_main.html").unwrap();
let html_file = File::open("./tests/data/tree_iterator/wikipedia_main.html").unwrap();
let mut char_iter = CharIterator::new();
let _ = char_iter.read_from_file(html_file, Some(gosub_engine::bytes::Encoding::UTF8));
char_iter.set_confidence(gosub_engine::bytes::Confidence::Certain);
Expand All @@ -46,7 +46,7 @@ fn stackoverflow_home(c: &mut Criterion) {
group.significance_level(0.1).sample_size(500);

// using the main page of (english) wikipedia as a rough estimate of traversing a decently sized website
let html_file = File::open("tests/data/tree_iterator/stackoverflow.html").unwrap();
let html_file = File::open("./tests/data/tree_iterator/stackoverflow.html").unwrap();
let mut char_iter = CharIterator::new();
let _ = char_iter.read_from_file(html_file, Some(gosub_engine::bytes::Encoding::UTF8));
char_iter.set_confidence(gosub_engine::bytes::Confidence::Certain);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion src/bin/parser-test.rs → engine/src/bin/parser-test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use gosub_engine::testing::tree_construction::fixture::fixture_root_path;
use gosub_engine::testing::tree_construction::fixture::read_fixtures;
use gosub_engine::testing::tree_construction::result::ResultStatus;
use gosub_engine::testing::tree_construction::Harness;
use gosub_engine::testing::tree_construction::Test;
use std::path::PathBuf;

/// Holds the results from all tests that are executed
pub struct TotalTestResults {
Expand Down Expand Up @@ -30,7 +32,8 @@ fn main() {
};

let filenames = Some(&["tests15.dat"][..]);
let fixtures = read_fixtures(filenames).expect("fixtures");
let root = PathBuf::from("engine").join(fixture_root_path());
let fixtures = read_fixtures(root, filenames).expect("fixtures");

for fixture_file in fixtures {
println!(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ pub fn fixture_root_path() -> PathBuf {

/// Read tree construction fixtures from the given path. If no filenames are given, all
/// fixtures are read, otherwise only the fixes with the given filenames are read.
pub fn read_fixtures(filenames: Option<&[&str]>) -> Result<Vec<FixtureFile>, Error> {
pub fn read_fixtures(root: PathBuf, filenames: Option<&[&str]>) -> Result<Vec<FixtureFile>, Error> {
let filenames = filenames.unwrap_or_default();
let mut files = vec![];

for entry in fs::read_dir(fixture_root_path())? {
for entry in fs::read_dir(root)? {
let path = entry?.path();

// Check if the fixture is a correct fixture file and if it's allowed to be used
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DISABLED_CASES: &[&str] = &[
"<!doctype html><template><plaintext>a</template>b",
];

// See tests/data/html5lib-tests/tree-construction/ for other test files.
// See engine/tests/data/html5lib-tests/tree-construction/ for other test files.
#[test_case("tests1.dat")]
#[test_case("tests2.dat")]
#[test_case("tests3.dat")]
Expand Down
Loading

0 comments on commit 818620e

Please sign in to comment.