Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cmake dependency #34

Merged
merged 2 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
# 0.5.2

- Remove cmake dependency.
- Fix c++ stdlib detection for all targets by using `cc-rs`.

# 0.5.1

- Use correct c++ stdlib implementation on OpenHarmony OS.
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "fontsan"
version = "0.5.1"
version = "0.5.2"
authors = ["The Servo Project Developers"]
description = "Sanitiser for untrusted font files"
build = "build.rs"
Expand All @@ -11,4 +11,5 @@ libc = "0.2"
miniz-sys = "0.1.7"

[build-dependencies]
cmake = "0.1"
cc = { version = "1.0.89", features = ["parallel"] }
glob = "0.3.1"
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -11,7 +11,7 @@ To update:
* edit the `_TAG` variables at the top of the `src/deps/update_deps.sh` script
* $ `bash src/deps/update_deps.sh`
* $ `git add src/deps`
* Potentially adjust src/CMakeLists.txt to accommodate new and removed files from the dependencies
* Potentially adjust the `build.rs` to accommodate new and removed files from the dependencies
* make `cargo build` and `cargo test` work
* update the crate version number and the `CHANGELOG.md`

Expand Down
89 changes: 74 additions & 15 deletions build.rs
@@ -1,21 +1,80 @@
#![deny(warnings)]

extern crate cmake;
use std::path::{Path, PathBuf};

use std::env;
const BROTLI_INCLUDE_DIR: &str = "src/deps/brotli/c/include";
const LZ4_INCLUDE_DIR: &str = "src/deps/lz4/lib";
const OTS_INCLUDE_DIR: &str = "src/deps/ots/include";
const WOFF2_INCLUDE_DIR: &str = "src/deps/woff2/include";
const ZLIB_INCLUDE_DIR: &str = "src/fake-zlib";

fn build_lz4() {
cc::Build::new()
.file("src/deps/lz4/lib/lz4.c")
.compile("lz4");
}

fn build_ots() {
let ots_sources = glob::glob("src/deps/ots/src/*.cc")
.expect("Invalid glob pattern")
.collect::<Result<Vec<PathBuf>, _>>()
.expect("vendored ots sources not found");

cc::Build::new()
.cpp(true)
.files(ots_sources)
.include(OTS_INCLUDE_DIR)
.include(LZ4_INCLUDE_DIR)
.include(WOFF2_INCLUDE_DIR)
.include(ZLIB_INCLUDE_DIR)
.std("c++11")
.compile("ots");
}

fn build_brotli() {
let brotli_sources = glob::glob("src/deps/brotli/c/**/*.c")
.expect("Invalid glob pattern")
.collect::<Result<Vec<PathBuf>, _>>()
.expect("vendored brotli sources not found");

cc::Build::new()
.files(brotli_sources)
.include(BROTLI_INCLUDE_DIR)
.compile("brotli");
}

fn build_woff2() {
let woff2_dir = Path::new("src/deps/woff2/src");
let file_names = [
"table_tags.cc",
"variable_length.cc",
"woff2_common.cc",
"woff2_dec.cc",
"woff2_out.cc",
];
let woff2_sources = file_names.iter().map(|name| woff2_dir.join(name));

cc::Build::new()
.files(woff2_sources)
.include(WOFF2_INCLUDE_DIR)
.include(BROTLI_INCLUDE_DIR)
.std("c++11")
.warnings(false)
.compile("woff2");
}

fn build_ots_glue() {
cc::Build::new()
.file("src/ots_glue.cc")
.include(OTS_INCLUDE_DIR)
.std("c++11")
.compile("ots_glue");
}

fn main() {
let dst = cmake::Config::new("src").build();

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") || target.contains("ohos") {
println!("cargo:rustc-link-lib=c++");
} else if !target.contains("msvc") {
println!("cargo:rustc-link-lib=stdc++");
}
build_lz4();
build_ots();
build_brotli();
build_woff2();
build_ots_glue();
}
52 changes: 0 additions & 52 deletions src/CMakeLists.txt

This file was deleted.