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

Use Core Text on macOS, remove runtime dependencies for linux release binary #18

Closed
wants to merge 15 commits into from
Closed
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
32 changes: 21 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ on:

jobs:
lint_and_format_check:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down Expand Up @@ -42,11 +45,14 @@ jobs:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install freetype and fontconfig for macOS
if: ${{ runner.os == 'macOS' }}
- name: Install build tools for macOS
if: runner.os == 'macOS'
run: |
brew install pkg-config cmake freetype fontconfig
pkg-config --libs --static fontconfig
brew install pkg-config cmake

- name: Remove system libraries in Ubuntu for static build
if: runner.os == 'Linux'
run: sudo apt-get remove --purge libfontconfig1-dev libfreetype6-dev libexpat1-dev

- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -73,7 +79,8 @@ jobs:
id: build
run: |
cargo clean
cargo build --all-targets --all-features --jobs 1 -vv || echo "::set-output name=fail::1"
mkdir target
cargo build --jobs 1 -vv 2>&1 | tee target/build.log || echo "::set-output name=fail::1"

- name: Upload build result to artifact
if: steps.build.outputs.fail == '1'
Expand Down Expand Up @@ -130,11 +137,14 @@ jobs:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install freetype and fontconfig for macOS
if: ${{ runner.os == 'macOS' }}
- name: Install build tools for macOS
if: runner.os == 'macOS'
run: |
brew install pkg-config cmake freetype fontconfig
pkg-config --libs --static fontconfig
brew install pkg-config cmake

- name: Remove system libraries in Ubuntu for static build
if: runner.os == 'Linux'
run: sudo apt-get remove --purge libfontconfig1-dev libfreetype6-dev libexpat1-dev

- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -147,7 +157,7 @@ jobs:

- name: Build use release profile
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
run: cargo build --all-targets --all-features -vv --release
run: cargo build -vv --release

- name: Upload release binary to artifact
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- On macOS, use (and dynamic link to) Core Text API to find fonts and render glyph
- On Linux, static link to Fontconfig and FreeType, do not need then installed in system anymore

## 0.3.1

- Display help message directly when `char` arg are missing (Issue #11, Pr #12)
Expand Down
73 changes: 71 additions & 2 deletions Cargo.lock

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

16 changes: 13 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ categories = ["command-line-utilities", "text-processing", "visualization"]

[dependencies]
structopt = "0.3"
servo-fontconfig = "0.5"
once_cell = "1.3"
httparse = "1.3"
once_cell = "1"
httparse = "1"
freetype = "0.7"
crossterm = "0.17"

[target.'cfg(target_os = "linux")'.dependencies]
servo-fontconfig = "0.5"

[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.9"
core-text = "19"

[dependencies.tui]
version = "0.10"
default-features = false
features = ["crossterm"]

# TODO: Delete me if servo-fontconfig-sys's new version will use static lib built by dep -sys crates
[patch.crates-io]
servo-fontconfig-sys = { git = "https://github.com/7sDream/libfontconfig", branch = "build/use-dep-built-static-lib-when-possible" }
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ This is port from my early python script called [which_fonts_support][which_font
- Use [`Fontconfig`][fontconfig-home] library instead of depends on `fc-list` command installed
- Support preview in shell (powered by [`FreeType`][free-type-home]), no browser needed

## Dependencies
## Dependencies for Development or Build

This program needs `Fontconfig` and `FreeType` library to run, and some of their deps needs `cmake` to compile, so we need to install them before compile:
This program will build `Fontconfig`(on Linux only) and `FreeType`(on Linux and macOS) from source automatically if you haven't installed them to system.

- macOS: `brew install cmake freetype fontconfig`
So this program needs `pkg-config`, `CMake` and `make` as **dev only** dependencies.

- macOS: `brew install pkg-config cmake` (macOS has built-in `make` tools already)
- Linux: Please refer to the docs of your Linux distribution to figure out how to install them
- Win: Do not support Windows for now

If you just want to use it, please download prebuild binary from release page, no runtime dependencies needed.

## Install or Update

```bash
Expand Down
Loading