Skip to content

Commit

Permalink
Use subprojects
Browse files Browse the repository at this point in the history
  • Loading branch information
chrsan committed May 2, 2024
1 parent 02d7637 commit 5a125ad
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 108 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,15 @@ cd bindings/python
pip install .
```

### Build the Rust bindings

You'll need [Meson][1] and [Ninja][2] to build the [Rust][3] bindings.

```shell
cd bindings/rust
cargo run --example bidi
```

[1]: https://mesonbuild.com
[2]: https://ninja-build.org
[3]: https://www.rust-lang.org
7 changes: 2 additions & 5 deletions bindings/python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# ruff: noqa: F401 F821
from .lib import Font # type: ignore
from .types import FontStyle, Glyph, Path, PathVerb, Point, Transform

del lib
del types
from ._subset import Font # type: ignore
from ._types import FontStyle, Glyph, Path, PathVerb, Point, Transform

__all__ = [
"Font",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion bindings/python/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections.abc import Callable, Generator
from dataclasses import dataclass, field

from .lib import GlyphDrawer, Font, ShapeContext, find_best_font_match, text_runs # type: ignore
from ._subset import GlyphDrawer, Font, ShapeContext, find_best_font_match, text_runs # type: ignore
from .types import FontRun, FontStyle, Glyph, GlyphRun, Path, PathVerb, Point


Expand Down
18 changes: 11 additions & 7 deletions bindings/python/meson.build
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
project('subset-python', 'c', 'cpp', 'cython')

subdir('deps/extern')
subdir('deps/lib')
subset_proj = subproject(
'subset',
default_options: ['default_library=static'],
)

subset_dep = subset_proj.get_variable('subset_dep')

py = import('python').find_installation(pure: false)

py.extension_module(
'lib',
'_subset',
'subset.pyx',
cython_args: ['--module-name', 'lib'],
dependencies: subset_lib_dep,
cython_args: ['--module-name', '_subset'],
dependencies: subset_dep,
install: true,
subdir: 'subset',
)

python_sources = files(
'__init__.py',
'_subset.pyi',
'_types.py',
'layout.py',
'lib.pyi',
'py.typed',
'types.py',
)

py.install_sources(
Expand Down
3 changes: 3 additions & 0 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ version = "0.0.1"
requires-python = ">=3.11"
authors = [{ name = "Christer Sandberg", email = "[email protected]" }]
license = { file = "../../LICENSE" }

[tool.meson-python.args]
install = ["--skip-subprojects"]
3 changes: 3 additions & 0 deletions bindings/python/subprojects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
harfbuzz
sheenbidi
*.wrap
1 change: 1 addition & 0 deletions bindings/python/subprojects/subset/meson.build
1 change: 1 addition & 0 deletions bindings/python/subprojects/subset/src
1 change: 1 addition & 0 deletions bindings/python/subprojects/subset/subprojects
2 changes: 1 addition & 1 deletion bindings/python/subset.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from cpython.mem cimport PyMem_Malloc, PyMem_Free
from libc.stddef cimport size_t
from libc.stdint cimport int32_t, uint8_t, uint32_t

cdef extern from "deps/lib/subset.h":
cdef extern from "subset.h":
ctypedef struct SubsetGlyphDrawer:
pass

Expand Down
13 changes: 6 additions & 7 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ fn main() {
cmd.arg("setup");
cmd.arg("--buildtype");
cmd.arg(build_type);
cmd.arg("--default-library");
cmd.arg("static");
cmd.arg(&build_dir);
assert!(cmd.status().unwrap().success());
}
let mut cmd = Command::new("meson");
cmd.current_dir(&build_dir);
cmd.arg("compile");
assert!(cmd.status().unwrap().success());
println!("cargo:rustc-link-search=native={}", build_dir.display());
println!(
"cargo:rustc-link-search=native={}",
build_dir.join("extern").display()
build_dir.join("subprojects/harfbuzz").display()
);
println!(
"cargo:rustc-link-search=native={}",
build_dir.join("lib").display()
build_dir.join("subprojects/sheenbidi").display()
);
println!("cargo:rustc-link-lib=static=harfbuzz");
println!("cargo:rustc-link-lib=static=sheenbidi");
Expand All @@ -40,9 +43,5 @@ fn main() {
"cargo:rerun-if-changed={}",
root_dir.join("meson.build").display()
);
println!(
"cargo:rerun-if-changed={}",
root_dir.join("extern").display()
);
println!("cargo:rerun-if-changed={}", root_dir.join("lib").display());
println!("cargo:rerun-if-changed={}", root_dir.join("src").display());
}
10 changes: 0 additions & 10 deletions extern/deps.json

This file was deleted.

36 changes: 0 additions & 36 deletions extern/meson.build

This file was deleted.

14 changes: 0 additions & 14 deletions lib/meson.build

This file was deleted.

30 changes: 28 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
project('subset', 'c', 'cpp')

subdir('extern')
subdir('lib')
harfbuzz_proj = subproject(
'harfbuzz',
default_options: ['default_library=static'],
)

harfbuzz_dep = harfbuzz_proj.get_variable('harfbuzz_dep')

sheenbidi_proj = subproject(
'sheenbidi',
default_options: ['default_library=static'],
)

sheenbidi_dep = sheenbidi_proj.get_variable('sheenbidi_dep')

subset_inc = include_directories('src')
subset_sources = files('src/subset.cc')
subset_lib = library(
'subset',
subset_sources,
cpp_args: ['-std=c++17', '-fno-exceptions', '-fno-rtti'],
dependencies: [harfbuzz_dep, sheenbidi_dep],
include_directories: subset_inc,
)

subset_dep = declare_dependency(
include_directories: subset_inc,
link_with: subset_lib,
)
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions subprojects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
harfbuzz
sheenbidi
5 changes: 5 additions & 0 deletions subprojects/harfbuzz.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[wrap-git]
url = https://github.com/harfbuzz/harfbuzz.git
revision = 8.4.0
depth = 1
patch_directory = harfbuzz
4 changes: 4 additions & 0 deletions subprojects/sheenbidi.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
url = https://github.com/Tehreer/SheenBidi.git
revision = v2.7
depth = 1
25 changes: 0 additions & 25 deletions tools/download_deps.py

This file was deleted.

0 comments on commit 5a125ad

Please sign in to comment.