Skip to content

Commit

Permalink
use macros
Browse files Browse the repository at this point in the history
  • Loading branch information
xoudini committed Dec 23, 2024
1 parent 14a70ba commit aba453c
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/resolvers/libicu.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import os
import pathlib
import typing as t
from hatch_buildext import Macro


def _get_build_dir() -> pathlib.Path:
return pathlib.Path(os.environ["_BUILD_DIR"])


def get_sources(root: str) -> t.Sequence[str]:
def _quote(value: str) -> str:
return f'"{value}"'


def get_sources(root: str, /) -> t.Sequence[str]:
pyicu = pathlib.Path(root).joinpath("pyicu").absolute()
return list(map(str, pyicu.glob("**/*.cpp")))


def get_include_dirs(root: str) -> t.Sequence[str]:
def get_include_dirs(root: str, /) -> t.Sequence[str]:
path = _get_build_dir().joinpath("include").absolute()

if not path.exists():
Expand All @@ -21,7 +26,7 @@ def get_include_dirs(root: str) -> t.Sequence[str]:
return [str(path)]


def get_library_dirs(root: str) -> t.Sequence[str]:
def get_library_dirs(root: str, /) -> t.Sequence[str]:
path = _get_build_dir().joinpath("lib").absolute()

if not path.exists():
Expand All @@ -30,7 +35,7 @@ def get_library_dirs(root: str) -> t.Sequence[str]:
return [str(path)]


def get_libraries(root: str) -> t.Sequence[str]:
def get_libraries(root: str, /) -> t.Sequence[str]:
# NOTE: manylinux
return [
"icudata",
Expand All @@ -45,12 +50,19 @@ def get_libraries(root: str) -> t.Sequence[str]:
]


def get_extra_compile_args(root: str) -> t.Sequence[str]:
VERSION = os.environ["PYICU_VERSION"]
ICU_MAX_MAJOR_VERSION = os.environ["ICU_MAX_MAJOR_VERSION"]
def get_extra_compile_args(root: str, /) -> t.Sequence[str]:
# NOTE: required by pyicu
return ["-std=c++17"]


def get_macros(root: str, /) -> t.Sequence[Macro]:
return [
"-std=c++17",
# TODO: pass to define_macros instead
f'-DPYICU_VER="{VERSION}"',
f'-DPYICU_ICU_MAX_VER="{ICU_MAX_MAJOR_VERSION}"',
Macro(
name="PYICU_VER",
value=_quote(os.environ["PYICU_VERSION"]),
),
Macro(
name="PYICU_ICU_MAX_VER",
value=_quote(os.environ["ICU_MAX_MAJOR_VERSION"]),
),
]

0 comments on commit aba453c

Please sign in to comment.