cross-complie fribidi for windows arm64

This commit is contained in:
Nulano 2023-12-12 20:22:29 +01:00
parent 66c244af32
commit 1ecd19336f
3 changed files with 53 additions and 41 deletions

View File

@ -116,10 +116,7 @@ jobs:
& python.exe -m pip install -r .ci/requirements-cibw.txt & python.exe -m pip install -r .ci/requirements-cibw.txt
# Cannot cross-compile FriBiDi (only used for tests) & python.exe winbuild\build_prepare.py -v --no-imagequant --architecture=${{ matrix.arch }}
$FLAGS = ("--no-imagequant", "--architecture=${{ matrix.arch }}")
if ('${{ matrix.arch }}' -eq 'ARM64') { $FLAGS += "--no-fribidi" }
& python.exe winbuild\build_prepare.py -v @FLAGS
shell: pwsh shell: pwsh
- name: Build wheels - name: Build wheels
@ -163,14 +160,12 @@ jobs:
path: ./wheelhouse/*.whl path: ./wheelhouse/*.whl
- name: Prepare to upload FriBiDi - name: Prepare to upload FriBiDi
if: "matrix.arch != 'ARM64'"
run: | run: |
mkdir fribidi\${{ matrix.arch }} mkdir fribidi\${{ matrix.arch }}
copy winbuild\build\bin\fribidi* fribidi\${{ matrix.arch }} copy winbuild\build\bin\fribidi* fribidi\${{ matrix.arch }}
shell: cmd shell: cmd
- name: Upload fribidi.dll - name: Upload fribidi.dll
if: "matrix.arch != 'ARM64'"
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: fribidi name: fribidi

View File

@ -56,7 +56,9 @@ def cmd_nmake(
) )
def cmds_cmake(target: str | tuple[str, ...] | list[str], *params) -> list[str]: def cmds_cmake(
target: str | tuple[str, ...] | list[str], *params, build_dir: str = "."
) -> list[str]:
if not isinstance(target, str): if not isinstance(target, str):
target = " ".join(target) target = " ".join(target)
@ -73,10 +75,11 @@ def cmds_cmake(target: str | tuple[str, ...] | list[str], *params) -> list[str]:
"-DCMAKE_CXX_FLAGS=-nologo", "-DCMAKE_CXX_FLAGS=-nologo",
*params, *params,
'-G "{cmake_generator}"', '-G "{cmake_generator}"',
".", f'-B "{build_dir}"',
f"-S .",
] ]
), ),
f"{{cmake}} --build . --clean-first --parallel --target {target}", f'{{cmake}} --build "{build_dir}" --clean-first --parallel --target {target}',
] ]
@ -367,7 +370,14 @@ DEPS = {
"build": [ "build": [
cmd_copy(r"COPYING", r"{bin_dir}\fribidi-1.0.13-COPYING"), cmd_copy(r"COPYING", r"{bin_dir}\fribidi-1.0.13-COPYING"),
cmd_copy(r"{winbuild_dir}\fribidi.cmake", r"CMakeLists.txt"), cmd_copy(r"{winbuild_dir}\fribidi.cmake", r"CMakeLists.txt"),
*cmds_cmake("fribidi"), # generated tab.i files cannot be cross-compiled
" ^&^& ".join(
[
"if {architecture}==ARM64 cmd /c call {vcvarsall} x86",
*cmds_cmake("fribidi-gen", "-DARCH=x86", build_dir="build_x86"),
]
),
*cmds_cmake("fribidi", "-DARCH={architecture}"),
], ],
"bins": [r"*.dll"], "bins": [r"*.dll"],
}, },
@ -381,10 +391,9 @@ def find_msvs(architecture: str) -> dict[str, str] | None:
print("Program Files not found") print("Program Files not found")
return None return None
requires = ["-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"]
if architecture == "ARM64": if architecture == "ARM64":
tools = "Microsoft.VisualStudio.Component.VC.Tools.ARM64" requires += ["-requires", "Microsoft.VisualStudio.Component.VC.Tools.ARM64"]
else:
tools = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
try: try:
vspath = ( vspath = (
@ -395,8 +404,7 @@ def find_msvs(architecture: str) -> dict[str, str] | None:
), ),
"-latest", "-latest",
"-prerelease", "-prerelease",
"-requires", *requires,
tools,
"-property", "-property",
"installationPath", "installationPath",
"-products", "-products",
@ -707,11 +715,6 @@ if __name__ == "__main__":
disabled += ["libimagequant"] disabled += ["libimagequant"]
if args.no_fribidi: if args.no_fribidi:
disabled += ["fribidi"] disabled += ["fribidi"]
elif args.architecture == "ARM64" and platform.machine() != "ARM64":
import warnings
warnings.warn("Cross-compiling FriBiDi is currently not supported, disabling")
disabled += ["fribidi"]
prefs = { prefs = {
"architecture": args.architecture, "architecture": args.architecture,

View File

@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.12)
project(fribidi) project(fribidi)
add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_WARNINGS)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(lib) include_directories(lib)
function(extract_regex_1 var text regex) function(extract_regex_1 var text regex)
@ -27,12 +27,20 @@ function(fribidi_conf)
set(PACKAGE_BUGREPORT "https://github.com/fribidi/fribidi/issues/new") set(PACKAGE_BUGREPORT "https://github.com/fribidi/fribidi/issues/new")
set(SIZEOF_INT 4) set(SIZEOF_INT 4)
set(FRIBIDI_MSVC_BUILD_PLACEHOLDER "#define FRIBIDI_BUILT_WITH_MSVC") set(FRIBIDI_MSVC_BUILD_PLACEHOLDER "#define FRIBIDI_BUILT_WITH_MSVC")
message("detected ${PACKAGE_NAME} version ${FRIBIDI_VERSION}") message("Detected ${PACKAGE_NAME} version ${FRIBIDI_VERSION}")
configure_file(lib/fribidi-config.h.in lib/fribidi-config.h @ONLY) configure_file(lib/fribidi-config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/lib/fribidi-config.h @ONLY)
endfunction() endfunction()
fribidi_conf() fribidi_conf()
option(ARCH "Target architecture")
if(${ARCH} STREQUAL ARM64)
set(GEN FALSE)
else()
set(GEN TRUE)
endif()
message("Generate tab.i files: " ${GEN})
function(prepend var prefix) function(prepend var prefix)
set(out "") set(out "")
foreach(f ${ARGN}) foreach(f ${ARGN})
@ -56,7 +64,8 @@ macro(fribidi_definitions _TGT)
endmacro() endmacro()
function(fribidi_gen _NAME _OUTNAME _PARAM) function(fribidi_gen _NAME _OUTNAME _PARAM)
set(_OUT lib/${_OUTNAME}) set(_OUT ${CMAKE_CURRENT_SOURCE_DIR}/lib/${_OUTNAME})
if(GEN)
prepend(_DEP "${CMAKE_CURRENT_SOURCE_DIR}/gen.tab/" ${ARGN}) prepend(_DEP "${CMAKE_CURRENT_SOURCE_DIR}/gen.tab/" ${ARGN})
add_executable(gen-${_NAME} add_executable(gen-${_NAME}
gen.tab/gen-${_NAME}.c gen.tab/gen-${_NAME}.c
@ -68,6 +77,7 @@ function(fribidi_gen _NAME _OUTNAME _PARAM)
COMMAND gen-${_NAME} ${_PARAM} ${_DEP} > ${_OUT} COMMAND gen-${_NAME} ${_PARAM} ${_DEP} > ${_OUT}
DEPENDS ${_DEP} DEPENDS ${_DEP}
OUTPUT ${_OUT}) OUTPUT ${_OUT})
endif(GEN)
list(APPEND FRIBIDI_SOURCES_GENERATED "${_OUT}") list(APPEND FRIBIDI_SOURCES_GENERATED "${_OUT}")
set(FRIBIDI_SOURCES_GENERATED ${FRIBIDI_SOURCES_GENERATED} PARENT_SCOPE) set(FRIBIDI_SOURCES_GENERATED ${FRIBIDI_SOURCES_GENERATED} PARENT_SCOPE)
endfunction() endfunction()
@ -78,8 +88,10 @@ fribidi_gen(unicode-version fribidi-unicode-version.h ""
macro(fribidi_tab _NAME) macro(fribidi_tab _NAME)
fribidi_gen(${_NAME}-tab ${_NAME}.tab.i 2 ${ARGN}) fribidi_gen(${_NAME}-tab ${_NAME}.tab.i 2 ${ARGN})
if(GEN)
target_sources(gen-${_NAME}-tab target_sources(gen-${_NAME}-tab
PRIVATE lib/fribidi-unicode-version.h) PRIVATE lib/fribidi-unicode-version.h)
endif(GEN)
endmacro() endmacro()
fribidi_tab(bidi-type unidata/UnicodeData.txt) fribidi_tab(bidi-type unidata/UnicodeData.txt)
@ -89,6 +101,8 @@ fribidi_tab(mirroring unidata/BidiMirroring.txt)
fribidi_tab(brackets unidata/BidiBrackets.txt unidata/UnicodeData.txt) fribidi_tab(brackets unidata/BidiBrackets.txt unidata/UnicodeData.txt)
fribidi_tab(brackets-type unidata/BidiBrackets.txt) fribidi_tab(brackets-type unidata/BidiBrackets.txt)
add_custom_target(fribidi-gen DEPENDS ${FRIBIDI_SOURCES_GENERATED})
file(GLOB FRIBIDI_SOURCES lib/*.c) file(GLOB FRIBIDI_SOURCES lib/*.c)
file(GLOB FRIBIDI_HEADERS lib/*.h) file(GLOB FRIBIDI_HEADERS lib/*.h)