Skip to content

Commit e8dd681

Browse files
authored
Port xetex_layout to Rust (#1138)
1 parent fe11279 commit e8dd681

37 files changed

Lines changed: 3722 additions & 4067 deletions

.github/actions/build-and-test/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ runs:
5252
- name: "cargo build for ${{ inputs.target }}"
5353
shell: bash
5454
run: |
55-
${{ inputs.executable }} build --all --target ${{ inputs.target }} --release ${{ steps.set-feature-flags.outputs.cargo-features }} $CARGO_VERBOSE
55+
${{ inputs.executable }} build --workspace --target ${{ inputs.target }} --release ${{ steps.set-feature-flags.outputs.cargo-features }} $CARGO_VERBOSE
5656
- name: "cargo test"
5757
shell: bash
5858
run: |
59-
${{ inputs.executable }} test --all --target ${{ inputs.target }} ${{ inputs.test-flags }} --release ${{ steps.set-feature-flags.outputs.cargo-features }} $CARGO_VERBOSE
59+
${{ inputs.executable }} test --workspace --target ${{ inputs.target }} ${{ inputs.test-flags }} --release ${{ steps.set-feature-flags.outputs.cargo-features }} $CARGO_VERBOSE
6060
- name: "Package test failure files"
6161
id: package-tests
6262
if: ${{ failure() }}

.github/workflows/build_and_test.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "Build and Test"
22

3-
on: [workflow_call]
3+
on: [ workflow_call ]
44

55
jobs:
66
clippy:
@@ -68,12 +68,12 @@ jobs:
6868
run: |
6969
artifact_dir="appimage"
7070
mkdir -p "$artifact_dir"
71-
71+
7272
if [[ $SOURCE_BRANCH == master ]] ; then
7373
export TECTONIC_APPIMAGE_TAG=continuous
7474
export UPDATE_INFORMATION="gh-releases-zsync|tectonic-typesetting|tectonic|continuous|tectonic-*.AppImage.zsync"
7575
fi
76-
76+
7777
./dist/appimage/build.sh
7878
cp dist/appimage/tectonic-*.AppImage* "$artifact_dir"
7979
env:
@@ -141,7 +141,7 @@ jobs:
141141
runs-on: ubuntu-latest
142142
strategy:
143143
matrix:
144-
toolchain: ["beta", "nightly"]
144+
toolchain: [ "beta", "nightly" ]
145145
fail-fast: false
146146
steps:
147147
- name: Checkout repository
@@ -166,7 +166,7 @@ jobs:
166166
linux-feature-tests:
167167
strategy:
168168
matrix:
169-
features: ["_all_", "_none_", "geturl-curl serialization"]
169+
features: [ "_all_", "_none_", "geturl-curl serialization" ]
170170
fail-fast: false
171171
runs-on: ubuntu-latest
172172
steps:
@@ -193,8 +193,8 @@ jobs:
193193
pkg-config:
194194
strategy:
195195
matrix:
196-
image: [ubuntu-latest, windows-latest, macos-latest]
197-
install-all-deps: [true, false]
196+
image: [ ubuntu-latest, windows-latest, macos-latest ]
197+
install-all-deps: [ true, false ]
198198
include:
199199
# By default, all items have toolchain: stable, and don't publish
200200
- toolchain: stable
@@ -327,12 +327,13 @@ jobs:
327327
echo "CROSS_ROOTLESS_CONTAINER_ENGINE=1" >> "$GITHUB_ENV"
328328
echo "DOCKER_OPTS=--privileged -e HOST_UID=${HOST_UID} -e HOST_GID=${HOST_GID}" >> "$GITHUB_ENV"
329329
# TODO: Add font files to the cross images so we can include fontconfig_bridge in tests
330+
# TODO: Figure out why doctests are broken so we can drop all-targets
330331
- name: "Build and Test"
331332
uses: ./.github/actions/build-and-test
332333
with:
333334
target: ${{ matrix.target }}
334335
publish: 'true'
335336
executable: 'cross'
336-
test-flags: '--exclude tectonic_bridge_fontconfig'
337+
test-flags: '--all-targets --exclude tectonic_bridge_fontconfig'
337338
package-flags: '--command-name=cross --reroot=.'
338339

Cargo.lock

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bridge_core/src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ impl<T: IoProvider> DriverHooks for MinimalDriver<T> {
194194
// Function defined in the C support code:
195195
extern "C" {
196196
fn _ttbc_get_error_message() -> *const libc::c_char;
197+
#[allow(improper_ctypes)]
198+
fn _ttbc_get_core_state() -> *mut CoreBridgeState<'static>;
197199
}
198200

199201
lazy_static::lazy_static! {
@@ -377,6 +379,18 @@ impl<'a> CoreBridgeState<'a> {
377379
}
378380
}
379381

382+
/// Get the current global bridge state. Uses a mutex to ensure unique access, and panics
383+
/// if no global state is set.
384+
pub fn with_global_state<T, F: for<'b> FnOnce(&mut CoreBridgeState<'b>) -> T>(f: F) -> T {
385+
/// Ensures we only enter the state once at a time, globally
386+
static GLOBAL: Mutex<()> = Mutex::new(());
387+
let _lock = GLOBAL.lock().unwrap();
388+
// SAFETY: Pointer is either null or valid, set by the engine on entrance
389+
let state = unsafe { _ttbc_get_core_state().as_mut() }
390+
.expect("Currently within an engine context in C");
391+
f(state)
392+
}
393+
380394
fn input_open_name_format(
381395
&mut self,
382396
name: &str,
@@ -637,7 +651,8 @@ impl<'a> CoreBridgeState<'a> {
637651
InputId::new(self.input_handles.len())
638652
}
639653

640-
fn input_get_size(&mut self, handle: InputId) -> usize {
654+
/// Get the size of an input. Prints a warning and returns 0 on error
655+
pub fn input_get_size(&mut self, handle: InputId) -> usize {
641656
let rhandle: &mut InputHandle = self.get_input(handle);
642657

643658
match rhandle.get_size() {
@@ -671,7 +686,8 @@ impl<'a> CoreBridgeState<'a> {
671686
rhandle.try_seek(pos)
672687
}
673688

674-
fn input_read(&mut self, handle: InputId, buf: &mut [u8]) -> Result<()> {
689+
/// Read from an input
690+
pub fn input_read(&mut self, handle: InputId, buf: &mut [u8]) -> Result<()> {
675691
let rhandle: &mut InputHandle = self.get_input(handle);
676692
rhandle.read_exact(buf).map_err(Error::from)
677693
}

crates/bridge_core/support/support.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ _ttbc_get_error_message(void)
113113
}
114114

115115

116+
ttbc_state_t *
117+
_ttbc_get_core_state(void)
118+
{
119+
return tectonic_global_bridge_core;
120+
}
121+
122+
116123
jmp_buf *
117124
ttbc_global_engine_enter(ttbc_state_t *api)
118125
{

crates/engine_xetex/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ links = "tectonic_engine_xetex"
2323
[dependencies]
2424
libc = "^0.2"
2525
tectonic_bridge_core = { path = "../bridge_core", version = "0.0.0-dev.0" }
26+
tectonic_bridge_freetype2 = { path = "../bridge_freetype2", version = "0.0.0-dev.0" }
2627
tectonic_bridge_flate = { path = "../bridge_flate", version = "0.0.0-dev.0" }
2728
tectonic_bridge_graphite2 = { path = "../bridge_graphite2", version = "0.0.0-dev.0" }
2829
tectonic_bridge_harfbuzz = { path = "../bridge_harfbuzz", version = "0.0.0-dev.0" }
30+
tectonic_bridge_icu = { path = "../bridge_icu", version = "0.0.0-dev.0" }
2931
tectonic_errors = { path = "../errors", version = "0.0.0-dev.0" }
3032
tectonic_pdf_io = { path = "../pdf_io", version = "0.0.0-dev.0" }
3133
tectonic_xetex_layout = { path = "../xetex_layout", version = "0.0.0-dev.0" }
@@ -42,9 +44,11 @@ external-harfbuzz = [
4244

4345
[package.metadata.internal_dep_versions]
4446
tectonic_bridge_core = "4e16bf963700aae59772a6fb223981ceaa9b5f57"
47+
tectonic_bridge_freetype2 = "fe112797308ca8aa0478cd31851ab75bc5afd43c"
4548
tectonic_bridge_flate = "5933308152efb6ba206b4dc01ab6814063b835c0"
4649
tectonic_bridge_graphite2 = "2c1ffcd702a662c003bd3d7d0ca4d169784cb6ad"
4750
tectonic_bridge_harfbuzz = "2c1ffcd702a662c003bd3d7d0ca4d169784cb6ad"
51+
tectonic_bridge_icu = "thiscommit:2023-09-17:6uIZ4lA"
4852
tectonic_cfg_support = "9d5feb40c7ac6958ee3c50604af9271eb2db2b20"
4953
tectonic_errors = "317ae79ceaa2593fb56090e37bf1f5cc24213dd9"
5054
tectonic_pdf_io = "9a8b975e76c7a27f140d0974ec3442f2347e18ad"

crates/engine_xetex/build.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ fn main() {
1818
let flate_include_dir = env::var("DEP_TECTONIC_BRIDGE_FLATE_INCLUDE").unwrap();
1919
let graphite2_include_path = env::var("DEP_GRAPHITE2_INCLUDE_PATH").unwrap();
2020
let graphite2_static = !env::var("DEP_GRAPHITE2_DEFINE_STATIC").unwrap().is_empty();
21+
let freetype_include_path = env::var("DEP_FREETYPE2_INCLUDE_PATH").unwrap();
2122
let harfbuzz_include_path = env::var("DEP_HARFBUZZ_INCLUDE_PATH").unwrap();
23+
let fontconfig_include_path = env::var("DEP_FONTCONFIG_INCLUDE_PATH");
24+
let icu_include_path = env::var("DEP_ICUUC_INCLUDE_PATH").unwrap();
2225

2326
// If we want to profile, the default assumption is that we must force the
2427
// compiler to include frame pointers. We whitelist platforms that are
@@ -76,11 +79,28 @@ fn main() {
7679
cxx_cfg.include(item);
7780
}
7881

82+
for item in freetype_include_path.split(';') {
83+
c_cfg.include(item);
84+
cxx_cfg.include(item);
85+
}
86+
7987
for item in graphite2_include_path.split(';') {
8088
c_cfg.include(item);
8189
cxx_cfg.include(item);
8290
}
8391

92+
for item in icu_include_path.split(';') {
93+
c_cfg.include(item);
94+
cxx_cfg.include(item);
95+
}
96+
97+
if let Ok(fc_includes) = fontconfig_include_path {
98+
for item in fc_includes.split(';') {
99+
c_cfg.include(item);
100+
cxx_cfg.include(item);
101+
}
102+
}
103+
84104
if graphite2_static {
85105
c_cfg.define("GRAPHITE2_STATIC", "1");
86106
cxx_cfg.define("GRAPHITE2_STATIC", "1");

crates/engine_xetex/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ mod linkage {
256256

257257
#[allow(unused_imports)]
258258
use tectonic_xetex_layout as clipyrenamehack2;
259+
260+
#[allow(unused_imports)]
261+
use tectonic_bridge_icu as clipyrenamehack3;
259262
}
260263

261264
/// Does our resulting executable link correctly?

0 commit comments

Comments
 (0)