From 6d0129b47abb6a544209e8b27dc9bb5f1eecd20a Mon Sep 17 00:00:00 2001 From: fasiondog Date: Tue, 9 Jan 2024 16:58:03 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E4=BA=A4=E5=8F=89?= =?UTF-8?q?=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ubuntu_aarch64.yml | 58 +++++++++++++++++++ .github/workflows/windows_python.yml | 2 +- hikyuu_extern_libs/packages/m/mysql/xmake.lua | 2 +- .../packages/p/pybind11/xmake.lua | 26 +++++++++ hikyuu_pywrap/xmake.lua | 33 +++++------ xmake.lua | 6 +- 6 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/ubuntu_aarch64.yml create mode 100644 hikyuu_extern_libs/packages/p/pybind11/xmake.lua diff --git a/.github/workflows/ubuntu_aarch64.yml b/.github/workflows/ubuntu_aarch64.yml new file mode 100644 index 000000000..30dd0b644 --- /dev/null +++ b/.github/workflows/ubuntu_aarch64.yml @@ -0,0 +1,58 @@ +name: ubuntu-aarch64-build + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + cross: [aarch64-linux-musl] + + concurrency: + group: ${{ github.ref }}-${{ github.base_ref }}-${{ github.head_ref }}-Cross-Musl-${{ matrix.cross }} + cancel-in-progress: true + + steps: + - uses: actions/checkout@v4 + + - name: Cache xmake aarch64 packages + id: cache-xmake-ubuntu-aarch64 + uses: actions/cache@v3 + env: + cache-name: cache-ubuntu-aarch64-modules + with: + path: | + ~/.xmake + ./${{ matrix.cross }}-cross.linux + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: branch@master + actions-cache-folder: '.xmake-cache' + + - name: Installation musl + run: | + wget https://github.com/xmake-mirror/musl.cc/releases/download/20210202/${{ matrix.cross }}-cross.linux.tgz + tar -xvf ${{ matrix.cross }}-cross.linux.tgz + + - name: configure + run: | + xmake f -p cross -a aarch64 --sdk=`pwd`/${{ matrix.cross }}-cross -y + + - name: build + run: | + xmake -b hikyuu diff --git a/.github/workflows/windows_python.yml b/.github/workflows/windows_python.yml index 035f3aead..9c5de22b8 100644 --- a/.github/workflows/windows_python.yml +++ b/.github/workflows/windows_python.yml @@ -45,7 +45,7 @@ jobs: - name: configure shell: cmd run: | - xmake f -y --pyver=3.11 + xmake f -y - name: build shell: cmd diff --git a/hikyuu_extern_libs/packages/m/mysql/xmake.lua b/hikyuu_extern_libs/packages/m/mysql/xmake.lua index 2bb1d61fd..c9297c27f 100644 --- a/hikyuu_extern_libs/packages/m/mysql/xmake.lua +++ b/hikyuu_extern_libs/packages/m/mysql/xmake.lua @@ -14,7 +14,7 @@ package("mysql") elseif is_plat("linux", "cross") and is_arch("aarch64", "arm64.*") then add_urls("https://github.com/fasiondog/hikyuu_extern_libs/releases/download/1.0.0/mysql-$(version)-linux-aarch64.zip", "https://gitee.com/fasiondog/hikyuu_extern_libs/releases/download/1.0.0/mysql-$(version)-linux-aarch64.zip") - add_versions("8.0.21", "5ceb31ddc75bfaa0ec5324fa1564dae3abdb7ea9d3f0763f10d06e871d21d7d4") + add_versions("8.0.21", "385a7e280f86aa864f02ae7061c940a20f1ace358f906d330453992331b638c8") end on_install("windows", "linux", "cross", function (package) diff --git a/hikyuu_extern_libs/packages/p/pybind11/xmake.lua b/hikyuu_extern_libs/packages/p/pybind11/xmake.lua new file mode 100644 index 000000000..1a6e24620 --- /dev/null +++ b/hikyuu_extern_libs/packages/p/pybind11/xmake.lua @@ -0,0 +1,26 @@ +package("pybind11") + + set_kind("library", {headeronly = true}) + set_homepage("https://github.com/pybind/pybind11") + set_description("Seamless operability between C++11 and Python.") + set_license("BSD-3-Clause") + + add_urls("https://github.com/pybind/pybind11/archive/$(version).zip", + "https://github.com/pybind/pybind11.git") + add_versions("v2.11.1", "b011a730c8845bfc265f0f81ee4e5e9e1d354df390836d2a25880e123d021f89") + + on_install(function (package) + os.cp("include", package:installdir()) + end) + + -- on_test(function (package) + -- assert(package:check_cxxsnippets({test = [[ + -- #include + -- int add(int i, int j) { + -- return i + j; + -- } + -- PYBIND11_MODULE(example, m) { + -- m.def("add", &add, "A function which adds two numbers"); + -- } + -- ]]}, {configs = {languages = "c++11"}})) + -- end) \ No newline at end of file diff --git a/hikyuu_pywrap/xmake.lua b/hikyuu_pywrap/xmake.lua index 65dcbaca7..35c63a1db 100644 --- a/hikyuu_pywrap/xmake.lua +++ b/hikyuu_pywrap/xmake.lua @@ -1,12 +1,5 @@ -option("pyver") - set_default("3.9") - set_showmenu(true) - set_category("hikyuu") - set_description("Use python version xy") -option_end() add_requires("pybind11", {system = false, alias = "pybind11"}) -add_requireconfs("pybind11.python", {override = true, system = false, version = get_config("pyver")}) target("core") set_kind("shared") @@ -42,19 +35,19 @@ target("core") add_rpathdirs("$ORIGIN", "$ORIGIN/lib", "$ORIGIN/../lib") - -- on_load(function(target) - -- import("lib.detect.find_tool") - -- import("lib.detect.find_path") - -- local python = assert(find_tool("python3", {version = true}), "python not found, please install it first! note: python version must > 3.0") - -- local exepath = path.directory(python.program) - -- if is_host("windows") then - -- includepath = find_path("Python.h", {exepath}, {suffixes = {"include"}}) - -- else - -- local pyver = python.version:match("%d+.%d+") - -- includepath = find_path("Python.h", {path.directory(exepath)}, {suffixes = {"include/python" .. pyver}}) - -- end - -- target:add("includedirs", includepath) - -- end) + on_load("windows", "linux", "macosx", function(target) + import("lib.detect.find_tool") + import("lib.detect.find_path") + local python = assert(find_tool("python3", {version = true}), "python not found, please install it first! note: python version must > 3.0") + local exepath = path.directory(python.program) + if is_host("windows") then + includepath = find_path("Python.h", {exepath}, {suffixes = {"include"}}) + else + local pyver = python.version:match("%d+.%d+") + includepath = find_path("Python.h", {path.directory(exepath)}, {suffixes = {"include/python" .. pyver}}) + end + target:add("includedirs", includepath) + end) after_build(function(target) if is_plat("macosx") then diff --git a/xmake.lua b/xmake.lua index 706139bff..ff5816ad6 100644 --- a/xmake.lua +++ b/xmake.lua @@ -154,13 +154,9 @@ add_requires("myboost " .. boost_version, { filesystem = true, serialization = true, system = false, - -- python = false, - -- pyver = get_config("pyver"), + python = false, }, }) --- if is_plat("windows") then --- add_requireconfs("myboost.python", {override = true, system=false}) --- end add_requires("spdlog", {system = false, configs = {header_only = true, fmt_external = true, vs_runtime = "MD"}}) add_requireconfs("spdlog.fmt", {override = true, version = fmt_version, configs = {header_only = true}}) From 184ed081bce121a4826d709b5b4f23726cda54e2 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Tue, 9 Jan 2024 18:40:30 +0800 Subject: [PATCH 2/3] update find python --- hikyuu_pywrap/xmake.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/hikyuu_pywrap/xmake.lua b/hikyuu_pywrap/xmake.lua index 35c63a1db..01982432b 100644 --- a/hikyuu_pywrap/xmake.lua +++ b/hikyuu_pywrap/xmake.lua @@ -37,16 +37,22 @@ target("core") on_load("windows", "linux", "macosx", function(target) import("lib.detect.find_tool") - import("lib.detect.find_path") - local python = assert(find_tool("python3", {version = true}), "python not found, please install it first! note: python version must > 3.0") - local exepath = path.directory(python.program) - if is_host("windows") then - includepath = find_path("Python.h", {exepath}, {suffixes = {"include"}}) - else - local pyver = python.version:match("%d+.%d+") - includepath = find_path("Python.h", {path.directory(exepath)}, {suffixes = {"include/python" .. pyver}}) + if is_plat("windows") then + -- detect installed python3 + local python = assert(find_tool("python", {version = true}), "python not found, please install it first! note: python version must > 3.0") + assert(python.version > "3", python.version .. " python version must > 3.0, please use python3.0 or later!") + -- find python include and libs directory + local pydir = os.iorun("python -c \"import sys; print(sys.executable)\"") + pydir = path.directory(pydir) + package:add("includedirs", pydir .. "/include") + package:add("linkdirs", pydir .. "/libs") + return end - target:add("includedirs", includepath) + + -- get python include directory. + local pydir = try { function () return os.iorun("python3-config --includes"):trim() end } + assert(pydir, "python3-config not found!") + package:add("cxflags", pydir) end) after_build(function(target) From 28d90f9c124180d6620c06febf1ee57b382affc8 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Tue, 9 Jan 2024 18:43:24 +0800 Subject: [PATCH 3/3] update --- hikyuu_pywrap/xmake.lua | 6 +++--- setup.py | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hikyuu_pywrap/xmake.lua b/hikyuu_pywrap/xmake.lua index 01982432b..b32d1d4ba 100644 --- a/hikyuu_pywrap/xmake.lua +++ b/hikyuu_pywrap/xmake.lua @@ -44,15 +44,15 @@ target("core") -- find python include and libs directory local pydir = os.iorun("python -c \"import sys; print(sys.executable)\"") pydir = path.directory(pydir) - package:add("includedirs", pydir .. "/include") - package:add("linkdirs", pydir .. "/libs") + target:add("includedirs", pydir .. "/include") + target:add("linkdirs", pydir .. "/libs") return end -- get python include directory. local pydir = try { function () return os.iorun("python3-config --includes"):trim() end } assert(pydir, "python3-config not found!") - package:add("cxflags", pydir) + target:add("cxflags", pydir) end) after_build(function(target) diff --git a/setup.py b/setup.py index 54031d4db..84f4c82de 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- from setuptools import setup, find_packages import sys @@ -10,9 +10,9 @@ import click -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # 前置检查 -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ def check_xmake(): """检查是否按照了编译工具 xmake""" print("checking xmake ...") @@ -25,7 +25,7 @@ def get_python_version(): py_version = platform.python_version_tuple() min_version = int(py_version[1]) main_version = int(py_version[0]) - #py_version = main_version * 10 + min_version if min_version < 10 else main_version * 100 + min_version + # py_version = main_version * 10 + min_version if min_version < 10 else main_version * 100 + min_version py_version = f"{main_version}.{min_version}" print(f'current python version: {py_version}') return py_version @@ -102,9 +102,9 @@ def clear_with_python_changed(mode): shutil.rmtree(build_pywrap_dir) -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # 执行构建 -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ def start_build(verbose=False, mode='release', feedback=True, worker_num=2): """ 执行编译 """ global g_verbose @@ -118,13 +118,13 @@ def start_build(verbose=False, mode='release', feedback=True, worker_num=2): py_version = current_compile_info['py_version'] - #如果 python版本或者编译模式发生变化,则编译依赖的 boost 库(boost.python) + # 如果 python版本或者编译模式发生变化,则编译依赖的 boost 库(boost.python) history_compile_info = get_history_compile_info() if py_version != history_compile_info[ 'py_version'] or history_compile_info['mode'] != mode: clear_with_python_changed(mode) - cmd = "xmake f {} -c -y -m {} --pyver={} --feedback={}".format( - "-v -D" if verbose else "", mode, py_version, feedback) + cmd = "xmake f {} -c -y -m {} --feedback={}".format( + "-v -D" if verbose else "", mode, feedback) print(cmd) os.system(cmd) @@ -143,9 +143,9 @@ def start_build(verbose=False, mode='release', feedback=True, worker_num=2): save_current_compile_info(current_compile_info) -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # 控制台命令 -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ @click.group() @@ -341,9 +341,9 @@ def upload(): os.system("twine upload dist/*") -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ # 添加 click 命令 -#------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ cli.add_command(build) cli.add_command(test) cli.add_command(clear)