Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Restore WASI SDK
uses: actions/cache/restore@v4
with:
path: ci_work_dir/wasi_sdk
path: ${{ env.XTASK_WORK_DIR }}/wasi_sdk
key: tools-wasi-sdk-${{ env.XTASK_WASI_SDK_VERSION }}
- name: Restore wasi-stub
uses: actions/cache/restore@v4
Expand All @@ -39,19 +39,19 @@ jobs:
- name: Restore wasm-opt
uses: actions/cache/restore@v4
with:
path: ci_work_dir/tools/wasm-opt
path: ${{ env.XTASK_WORK_DIR }}/tools/wasm-opt
key: tools-binaryen-${{ env.XTASK_BINARYEN_VERSION }}
- name: Restore typst
uses: actions/cache/restore@v4
with:
path: ci_work_dir/tools/typst
path: ${{ env.XTASK_WORK_DIR }}/tools/typst
key: tools-typst-${{ env.XTASK_TYPST_VERSION }}
- name: Run CI xtask
run: cargo xtask ci
- name: Cache WASI SDK
uses: actions/cache/save@v4
with:
path: ci_work_dir/wasi_sdk
path: ${{ env.XTASK_WORK_DIR }}/wasi_sdk
key: tools-wasi-sdk-${{ env.XTASK_WASI_SDK_VERSION }}
- name: Cache wasi-stub
uses: actions/cache/save@v4
Expand All @@ -63,12 +63,12 @@ jobs:
- name: Cache wasm-opt
uses: actions/cache/save@v4
with:
path: ci_work_dir/tools/wasm-opt
path: ${{ env.XTASK_WORK_DIR }}/tools/wasm-opt
key: tools-binaryen-${{ env.XTASK_BINARYEN_VERSION }}
- name: Cache typst
uses: actions/cache/save@v4
with:
path: ci_work_dir/tools/typst
path: ${{ env.XTASK_WORK_DIR }}/tools/typst
key: tools-typst-${{ env.XTASK_TYPST_VERSION }}
- uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion typst-package/example.typ → dist/example.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#import "./lib.typ" as tiaoma
#import "../typst-package/lib.typ" as tiaoma
// #import "@preview/tiaoma:0.1.0"
#set page(width: auto, height: auto)

Expand Down
Binary file added dist/fonts/CascadiaNextSC.wght.ttf
Binary file not shown.
8 changes: 4 additions & 4 deletions typst-package/manual.typ → dist/manual.typ
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#import "./lib.typ": *
#import "./lib.typ"
#import "../typst-package/lib.typ": *
#import "../typst-package/lib.typ"
#import "@preview/tidy:0.2.0"
#import "@preview/tablex:0.0.8": tablex, colspanx, cellx
#import "./tidy_style.typ"
#import "../dist/tidy_style.typ"

#set page(
paper: "a4",
Expand Down Expand Up @@ -102,7 +102,7 @@ Some generators require additional configuration (such as composite codes), this
)

#let docs = tidy.parse-module(
read("lib.typ"),
read("../typst-package/lib.typ"),
name: "tiaoma",
scope: (tiaoma: lib, typst-type: typst-type, typst-val: typst-val, l: l),
)
Expand Down
2 changes: 1 addition & 1 deletion typst-package/tidy_style.typ → dist/tidy_style.typ
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
pad(
x: 10pt,
{
set text(font: "Cascadia Mono", size: 0.85em, weight: 340)
set text(font: "Cascadia Next", size: 0.85em, weight: 340)
text(
fn.name,
fill: style-args.colors.at(
Expand Down
Binary file modified typst-package/manual.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ license.workspace = true

xxhash-rust = { version = "0.8", features = ["xxh3"] }
walkdir = { workspace = true }
memchr = { version = "2", default-features = false }
157 changes: 77 additions & 80 deletions xtask/src/action_impl.rs → xtask/src/action/impl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::{ffi::OsStr, os::unix::ffi::OsStringExt, path::PathBuf};
use std::{ffi::OsStr, path::PathBuf};

use super::*;
use crate::state::GlobalState;
use super::macros::*;
use super::ActionResult;

use crate::arguments::ArgumentList;
use crate::log::*;
use crate::state::{configure, GlobalState};
use crate::tools::*;
use crate::{state, state_path};

Expand Down Expand Up @@ -30,7 +34,7 @@ fn wasi_url(version: impl AsRef<str>) -> String {
panic!("no prebuild WASI SDK available for current platform; please build and specify `WASI_SDK_PATH` environment variable manually")
}

pub fn action_ensure_wasi_sdk(_args: &[String]) -> ActionResult {
pub fn action_ensure_wasi_sdk(_args: &ArgumentList) -> ActionResult {
if has_wasi_sdk() {
action_skip!("WASI SDK is set with environment variable");
}
Expand Down Expand Up @@ -65,26 +69,37 @@ pub fn action_ensure_wasi_sdk(_args: &[String]) -> ActionResult {
action_ok!();
}

pub fn action_build_plugin(args: &[String]) -> ActionResult {
pub fn action_build_plugin(args: &ArgumentList) -> ActionResult {
GlobalState::set_temporary(
"BUILD_PROFILE",
match args.contains(&"--debug".to_string()) {
match args.has("debug") {
true => "plugin-debug",
false => "plugin-release",
},
);

action_expect!(cargo([
"build".to_string(),
"--profile".to_string(),
GlobalState::set_temporary("PREV_PLUGIN_WASM_HASH", state!(PLUGIN_WASM_HASH));
GlobalState::set(
"PLUGIN_WASM_HASH",
hash_configured_paths!([
"$<root>/zint-wasm-sys/src",
"$<root>/zint-wasm-sys/build.rs",
"$<root>/zint-wasm-rs/src",
"$<root>/zint-typst-plugin/src",
])
.to_string(),
);
action_expect!(cargo((
"build",
"--profile",
state!(BUILD_PROFILE),
"--target".to_string(),
"--target",
state!(TARGET)
]));
)));
action_ok!();
}

pub fn action_stub_plugin(args: &[String]) -> ActionResult {
pub fn action_stub_plugin(args: &ArgumentList) -> ActionResult {
let release = state_path!(PROJECT_ROOT)
.join("target")
.join(state!(TARGET))
Expand All @@ -95,20 +110,11 @@ pub fn action_stub_plugin(args: &[String]) -> ActionResult {
.join(state!(BUILD_PROFILE))
.join(state!(PLUGIN_STUB_WASM, default: "plugin_stub.wasm"));

let input_changed = did_files_change!([
"$<root>/zint-wasm-sys/src",
"$<root>/zint-wasm-sys/build.rs",
"$<root>/zint-wasm-rs/src",
"$<root>/zint-typst-plugin/src",
] as PLUGIN_WASM_HASH);
let input_changed = state!(PREV_PLUGIN_WASM_HASH) != state!(PLUGIN_WASM_HASH);
if !exists(&stub_path) || input_changed {
group!("Stubbing '{}'", release.display());
action_expect!(wasi_stub(release, &stub_path));
end_group!();

if input_changed {
GlobalState::set("PLUGIN_WASM_STUB_HASH", state!(PLUGIN_WASM_HASH));
}
}

// report stubbed file size because WASI module can't actually be ran by
Expand All @@ -117,7 +123,7 @@ pub fn action_stub_plugin(args: &[String]) -> ActionResult {
"- Compiled WASM size: {}",
action_expect!(FileSize::of(&stub_path))
);
if args.contains(&"--debug".to_string()) {
if args.has("debug") {
let target_path =
state_path!(TYPST_PKG).join(state!(PLUGIN_WASM_OUT, default: "plugin.wasm"));
action_expect!(std::fs::copy(stub_path, target_path));
Expand All @@ -141,8 +147,8 @@ fn binaryen_url(version: impl AsRef<str>) -> String {
panic!("no prebuild binaryen available for current platform")
}

pub fn action_prepare_wasm_opt(args: &[String]) -> ActionResult {
if args.contains(&"--debug".to_string()) {
pub fn action_prepare_wasm_opt(args: &ArgumentList) -> ActionResult {
if args.has("debug") {
action_skip!("building in debug mode");
}
if has_command(WASM_OPT) {
Expand All @@ -164,20 +170,20 @@ pub fn action_prepare_wasm_opt(args: &[String]) -> ActionResult {
action_expect!(untar(
binaryen_tar,
wasm_opt_dir,
[
"--strip-components=2".to_string(),
(
"--strip-components=2",
format!(
"binaryen-version_{}/bin/{WASM_OPT}",
state!(BINARYEN_VERSION, default: "119")
)
]
)
));
}
action_ok!();
}

pub fn action_opt_plugin(args: &[String]) -> ActionResult {
if args.contains(&"--debug".to_string()) {
pub fn action_opt_plugin(args: &ArgumentList) -> ActionResult {
if args.has("debug") {
action_skip!("building in debug mode");
}
let base_path = state_path!(WORK_DIR)
Expand All @@ -188,77 +194,70 @@ pub fn action_opt_plugin(args: &[String]) -> ActionResult {
base_path.join(state!(PLUGIN_STUB_OPT_WASM, default: "plugin_stub_opt.wasm"));
let target_path = state_path!(TYPST_PKG).join(state!(PLUGIN_WASM_OUT, default: "plugin.wasm"));

let stub_hash = state!(PLUGIN_WASM_STUB_HASH, default: "");
let input_changed = state!(PLUGIN_WASM_HASH) != stub_hash;
let input_changed = state!(PREV_PLUGIN_WASM_HASH) != state!(PLUGIN_WASM_HASH);
if !exists(&stub_opt_path) || input_changed {
action_expect!(wasm_opt(stub_path, &stub_opt_path));
action_expect!(std::fs::copy(stub_opt_path, &target_path));
}
GlobalState::set("PLUGIN_WASM_HASH", stub_hash);
summary!(
"- Optimized WASM size: {}",
action_expect!(FileSize::of(target_path))
);
action_ok!();
}

pub fn action_build_manual(_args: &[String]) -> ActionResult {
let manual_source = state_path!(MANUAL_SOURCE, default: || {
state_path!(TYPST_PKG).join("manual.typ").to_string_lossy().to_string()
});
pub fn action_build_manual(_args: &ArgumentList) -> ActionResult {
let manual_source = state_path!(TYPST_MANUAL_SOURCE, default: "$<root>/dist/manual.typ");
let manual_target = state_path!(TYPST_PKG).join("manual.pdf");
action_expect!(typst_compile(&manual_source, &manual_target));

#[cfg(not(ci))]
{
if did_files_change!([manual_source] as MANUAL_HASH) {
cmd(
"git",
[
OsStr::new("update-index"),
OsStr::new("--no-assume-unchanged"),
manual_target.as_os_str(),
],
);
cmd(
"git",
[
OsStr::new("add"),
manual_target.as_os_str(),
],
);
} else {
cmd(
"git",
[
OsStr::new("update-index"),
OsStr::new("--assume-unchanged"),
manual_target.as_os_str(),
],
);
}
}

let create_time = action_expect!(last_edit(&manual_source));
action_expect!(typst_compile(
&manual_source,
&manual_target,
(
"--root",
state!(PROJECT_ROOT),
"--ignore-system-fonts",
"--font-path",
configure!("$<root>/dist/fonts"),
"--creation-timestamp",
create_time.to_string(),
)
));
GlobalState::set("MANUAL_CHANGE_TIME", create_time.to_string());

action_ok!();
}

pub fn action_build_example(_args: &[String]) -> ActionResult {
let example_source = state_path!(MANUAL_SOURCE, default: || {
state_path!(TYPST_PKG).join("example.typ").to_string_lossy().to_string()
});
pub fn action_build_example(_args: &ArgumentList) -> ActionResult {
let example_source = state_path!(TYPST_EXAMPLE_SOURCE, default: "$<root>/dist/example.typ");
let example_target = state_path!(TYPST_PKG).join("example.svg");
action_expect!(typst_compile(example_source, example_target));

let create_time = action_expect!(last_edit(&example_source));
action_expect!(typst_compile(
example_source,
example_target,
(
"--root",
state!(PROJECT_ROOT),
"--ignore-system-fonts",
"--font-path",
configure!("$<root>/dist/fonts"),
"--creation-timestamp",
create_time.to_string(),
)
));
action_ok!();
}

pub fn action_ensure_cargo_about(_args: &[String]) -> ActionResult {
pub fn action_ensure_cargo_about(_args: &ArgumentList) -> ActionResult {
if !cargo_has_tool("cargo-about") {
action_expect!(cargo(["install", "cargo-about"]));
}
action_ok!();
}

pub fn action_make_3rdparty_license_list(_args: &[String]) -> ActionResult {
pub fn action_make_3rdparty_license_list(_args: &ArgumentList) -> ActionResult {
let about_input =
state_path!(THIRDPARTY_LICENSE_PATH, default: "$<root>/dist/3rdparty_license.hbs");
let output = cargo([
Expand All @@ -267,16 +266,14 @@ pub fn action_make_3rdparty_license_list(_args: &[String]) -> ActionResult {
about_input.as_os_str(),
]);
let output = action_expect!(action_expect!(output).output());
let generated = std::ffi::OsString::from_vec(output.stdout)
.to_string_lossy()
.to_string();
let generated = action_expect!(std::str::from_utf8(&output.stdout));

let about_output_file = state_path!(TYPST_PKG).join("3rdparty_license.html");
action_expect!(std::fs::write(about_output_file, generated));
action_ok!();
}

pub fn action_copy_license(_args: &[String]) -> ActionResult {
pub fn action_copy_license(_args: &ArgumentList) -> ActionResult {
let source_path = state_path!(LICENSE_FILE, default: "$<root>/LICENSE");
let target_path = state_path!(TYPST_PKG).join("LICENSE");
action_expect!(std::fs::copy(source_path, target_path));
Expand All @@ -302,7 +299,7 @@ fn typst_url(version: impl AsRef<str>) -> (String, &'static str, &'static str) {
}

// should be only used for CI
pub fn action_install_typst(_args: &[String]) -> ActionResult {
pub fn action_install_typst(_args: &ArgumentList) -> ActionResult {
if has_command(TYPST) {
action_skip!("{} already in PATH", TYPST);
}
Expand Down
16 changes: 1 addition & 15 deletions xtask/src/action_macros.rs → xtask/src/action/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,11 @@ macro_rules! declare_actions {
}

/// Provides optionally executed logic by an action.
pub fn runner(self) -> Option<fn(&[String]) -> ActionResult> {
pub fn runner(self) -> Option<fn(&ArgumentList) -> ActionResult> {
match self {
$(Self::$action => $runner,)*
}
}
}
};
}

macro_rules! did_files_change {
([$($files: expr),+ $(,)?] as $backing: expr) => {{
let hash = hash_files([$(
$crate::state::Configure::configure($files, $crate::state::GlobalState)
),*]).to_string();
if hash == state!($backing, default: "") {
false
} else {
$crate::state::GlobalState::set(stringify!($backing), hash);
true
}
}};
}
Loading