Skip to content

Commit

Permalink
Fix windows build and add github CI (servo#26)
Browse files Browse the repository at this point in the history
* Minor improvements to CMake code

- cmake_minimum_required must be before the project call
- Bump the minimum supported CMake version to something reasonable
  (CMake 3.13 is shipped in debian 10 buster)

* Fix cargo deprecation warnings

* Statically link LZ4 on windows

statically link into lz4 on windows to fix executables not linking on windows.
Presumably on Linux / darwin lz4 is available as a dynamic library.

a more proper solution might be to first search for the library
and then fallback to static linking only if
CMake can't find lz4.

* Reorder link-lib lines

brotli is linked into woff2 is linked into ots,
so the order of `-l` lines should be
1. ots
2. woff2
3. brotli

Some linkers may not care about the order and also scan right
to left (e.g. lld), but this is not a given.

* Add missing brotli files (missing symbols on windows)

add all enc files

* Add github CI workflow

* Update .github/workflows/test.yml

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
  • Loading branch information
jschwe and mrobinson authored Jan 31, 2024
1 parent 29e879c commit 0e9bc74
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on: [push, pull_request]

jobs:
build_and_test:
name: Build and Test
strategy:
matrix:
os:
- "ubuntu-latest"
- "macos-latest"
- "windows-latest"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Build
run: cargo build -vv
- name: Test
run: cargo test -vv
env:
RUST_BACKTRACE: 1

build_result:
name: Result
runs-on: ubuntu-latest
needs:
- "build_and_test"
steps:
- name: Mark the job as successful
if: ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
run: exit 0
- name: Mark the job as unsuccessful
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1

9 changes: 4 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use std::env;
fn main() {
let dst = cmake::Config::new("src").build();

println!("cargo:rustc-link-search=native={}/lib\n\
cargo:rustc-link-lib=static=brotli\n\
cargo:rustc-link-lib=static=woff2\n\
cargo:rustc-link-lib=static=ots",
dst.display());
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=ots");
println!("cargo:rustc-link-lib=static=woff2");
println!("cargo:rustc-link-lib=static=brotli");
let target = env::var("TARGET").unwrap();
if target.contains("apple") {
println!("cargo:rustc-link-lib=c++");
Expand Down
32 changes: 28 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.13)
project(ots)
cmake_minimum_required(VERSION 2.6)

# Needed to avoid error
set(DUMMY ${CMAKE_BUILD_TYPE})

set(OTS_SOURCES
ots/src/cff.cc
Expand Down Expand Up @@ -97,6 +94,23 @@ set(BROTLI_SOURCES
ots/third_party/brotli/c/include/brotli/decode.h
ots/third_party/brotli/c/include/brotli/port.h
ots/third_party/brotli/c/include/brotli/types.h
ots/third_party/brotli/c/enc/backward_references.c
ots/third_party/brotli/c/enc/backward_references_hq.c
ots/third_party/brotli/c/enc/bit_cost.c
ots/third_party/brotli/c/enc/block_splitter.c
ots/third_party/brotli/c/enc/brotli_bit_stream.c
ots/third_party/brotli/c/enc/cluster.c
ots/third_party/brotli/c/enc/compress_fragment.c
ots/third_party/brotli/c/enc/compress_fragment_two_pass.c
ots/third_party/brotli/c/enc/dictionary_hash.c
ots/third_party/brotli/c/enc/encode.c
ots/third_party/brotli/c/enc/entropy_encode.c
ots/third_party/brotli/c/enc/histogram.c
ots/third_party/brotli/c/enc/literal_cost.c
ots/third_party/brotli/c/enc/memory.c
ots/third_party/brotli/c/enc/metablock.c
ots/third_party/brotli/c/enc/static_dict.c
ots/third_party/brotli/c/enc/utf8_util.c
)

set(WOFF2_SOURCES
Expand Down Expand Up @@ -131,6 +145,11 @@ set(OTS_GLUE_SOURCES
ots_glue.cc
)

set(LZ4_SOURCES
ots/third_party/lz4/lib/lz4.c
ots/third_party/lz4/lib/lz4.h
)

include_directories(
fake-zlib
ots/include
Expand All @@ -148,6 +167,11 @@ add_library(brotli STATIC ${BROTLI_SOURCES})
add_library(woff2 STATIC ${WOFF2_SOURCES})
add_library(ots_glue STATIC ${OTS_GLUE_SOURCES})

if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_sources(ots PRIVATE "${LZ4_SOURCES}")
target_include_directories(ots PRIVATE ots/third_party/lz4/lib/)
endif()

SET_TARGET_PROPERTIES(woff2 PROPERTIES
COMPILE_FLAGS "-std=c++11"
)
Expand Down
2 changes: 1 addition & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub trait Wr: Write + Seek { }
impl<T> Wr for T where T: Write + Seek { }

pub struct RustOTSStream<'a> {
pub wr: &'a mut (Wr + 'a),
pub wr: &'a mut (dyn Wr + 'a),
pub error: Option<io::Error>,
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn process_and_write<W>(output: &mut W, font_data: &[u8]) -> Result<(), Erro
#[inline]
pub fn process(font_data: &[u8]) -> Result<Vec<u8>, Error> {
let mut out = io::Cursor::new(vec![]);
try!(process_and_write(&mut out, font_data));
process_and_write(&mut out, font_data)?;
Ok(out.into_inner())
}

Expand Down

0 comments on commit 0e9bc74

Please sign in to comment.