Skip to content

Commit

Permalink
Add support for web assembly output
Browse files Browse the repository at this point in the history
  • Loading branch information
vicapow committed Nov 19, 2024
1 parent 87f0cf9 commit 2b6a985
Show file tree
Hide file tree
Showing 76 changed files with 395 additions and 98 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Test
run: cargo test
run: cargo test --all
format:
name: Cargo format (${{ matrix.os }})
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -56,11 +56,11 @@ jobs:
name: Nix build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix build
- run: nix flake check --all-systems
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix build
- run: nix flake check --all-systems
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/debug/
tex-fmt-lib/tests/target
/target/
**/*.rs.bk
*.pdb
Expand All @@ -11,3 +12,4 @@ perf.data*
*.pdf
*.png
cachegrind.out
tex-fmt-wasm/pkg
121 changes: 121 additions & 0 deletions Cargo.lock

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

25 changes: 18 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
[workspace]
members = [
"tex-fmt-lib",
".",
"tex-fmt-wasm",
]

[package]
name = "tex-fmt"
edition = "2021"

[workspace.package]
version = "0.4.7"
authors = ["William George Underwood"]
license = "MIT"
Expand All @@ -10,14 +20,15 @@ keywords = ["latex", "formatter"]
categories = ["command-line-utilities", "development-tools"]
exclude = ["tests/*", "extra/*", "*.nix", ".github/*"]

[[bin]]
name = "bin"
path = "src/main.rs"

[dependencies]
clap = { version = "4.5.21", features = ["derive"] }
colored = "2.1.0"
env_logger = "0.11.5"
lazy_static = "1.5.0"
log = "0.4.22"
regex = "1.11.1"
similar = "2.6.0"
tex-fmt-lib = { path = "./tex-fmt-lib" }

[workspace.dependencies]
fs = "0.0.5"

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:
@cargo build -r

test:
@cargo test
@cargo test --all

doc:
@cargo doc
Expand Down
83 changes: 6 additions & 77 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,81 +1,10 @@
//! tex-fmt
//! An extremely fast LaTeX formatter written in Rust

#![warn(missing_docs)]
#![warn(clippy::nursery)]
#![warn(clippy::cargo)]
#![warn(clippy::missing_docs_in_private_items)]
#![warn(clippy::pedantic)]
#![allow(clippy::wildcard_imports)]
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::module_name_repetitions)]
#[warn(unused_imports)]

use clap::Parser;
use std::fs;
use std::process::ExitCode;

mod cli;
mod comments;
mod format;
mod ignore;
mod indent;
mod logging;
mod read;
mod regexes;
mod subs;
mod verbatim;
mod wrap;
mod write;
use crate::cli::*;
use crate::format::*;
use crate::logging::*;
use crate::read::*;
use crate::write::*;

#[cfg(test)]
mod tests;

#[cfg(target_family = "unix")]
/// Line ending for unix
const LINE_END: &str = "\n";

#[cfg(target_family = "windows")]
/// Line ending for Windows
const LINE_END: &str = "\r\n";

fn main() -> ExitCode {
let mut args = Cli::parse();
init_logger(args.log_level());

let mut logs = Vec::<Log>::new();
let mut exit_code = args.resolve(&mut logs);

if exit_code == 0 {
if args.stdin {
// TODO combine the read and read_stdin functions to simplify this
if let Some((file, text)) = read_stdin(&mut logs) {
let new_text = format_file(&text, &file, &args, &mut logs);
exit_code = process_output(
&args, &file, &text, &new_text, exit_code, &mut logs,
);
} else {
exit_code = 1;
}
} else {
for file in &args.files {
if let Some((file, text)) = read(file, &mut logs) {
let new_text = format_file(&text, &file, &args, &mut logs);
exit_code = process_output(
&args, &file, &text, &new_text, exit_code, &mut logs,
);
} else {
exit_code = 1;
};
}
}
}

print_logs(&mut logs);
ExitCode::from(exit_code)
}
fn main() -> std::process::ExitCode {
let mut output: Option<String> = None;
let exit_code = tex_fmt_lib::run(None, &mut output);
std::process::ExitCode::from(exit_code)
}
29 changes: 29 additions & 0 deletions tex-fmt-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "tex-fmt-lib"
description = "tex-fmt compiled to web assembly"
version.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
edition.workspace = true
keywords.workspace = true
categories.workspace = true
exclude.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
clap = { version = "4.5.21", features = ["derive"] }
colored = "2.1.0"
env_logger = "0.11.5"
lazy_static = "1.5.0"
log = "0.4.22"
regex = "1.11.1"
similar = "2.6.0"
wasm-bindgen = "0.2"
web-time = "1.1.0"

[dependencies.web-sys]
version = "0.3"
features = ["console"]
1 change: 1 addition & 0 deletions src/cli.rs → tex-fmt-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl Cli {

/// Ensure the provided arguments are consistent
pub fn resolve(&mut self, logs: &mut Vec<Log>) -> u8 {

let mut exit_code = 0;
self.verbose |= self.trace;
self.print |= self.stdin;
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/format.rs → tex-fmt-lib/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn format_file(
args: &Cli,
logs: &mut Vec<Log>,
) -> String {

record_file_log(logs, Info, file, "Formatting started.");

// Clean the source file and zip its lines with line numbers
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 2b6a985

Please sign in to comment.