From f8fc748d77d34423739d6523814fa06b44588979 Mon Sep 17 00:00:00 2001 From: peefy Date: Mon, 26 Feb 2024 15:17:33 +0800 Subject: [PATCH] fix: kcl lib release folder Signed-off-by: peefy --- Cargo.toml | 2 +- install.go | 2 +- java/pom.xml | 2 +- python/kcl_lib/api/service.py | 9 +++- python/kcl_lib/bootstrap/__init__.py | 3 +- python/kcl_lib/bootstrap/artifact.py | 62 ++++++++++++++++++---------- python/setup.py | 21 ++++++++-- 7 files changed, 70 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a983cb65..f298c8a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kcl-lang" -version = "0.8.0-alpha.4" +version = "0.8.0-alpha.5" edition = "2021" readme = "README.md" documentation = "kcl-lang.io" diff --git a/install.go b/install.go index f54801d9..7b4961fc 100644 --- a/install.go +++ b/install.go @@ -8,7 +8,7 @@ import ( "runtime" ) -const KCLVM_VERSION = "v0.8.0-alpha.4" +const KCLVM_VERSION = "v0.8.0-alpha.5" func findPath(name string) string { if path, err := exec.LookPath(name); err == nil { diff --git a/java/pom.xml b/java/pom.xml index 1f3dc575..2135054a 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -6,7 +6,7 @@ com.kcl kcl-lib - 0.8.0-alpha.4 + 0.8.0-alpha.5 KCL Arifact Library for Java KCL is an open-source constraint-based record and functional language mainly diff --git a/python/kcl_lib/api/service.py b/python/kcl_lib/api/service.py index c717e405..38b00309 100644 --- a/python/kcl_lib/api/service.py +++ b/python/kcl_lib/api/service.py @@ -5,10 +5,11 @@ from kcl_lib.bootstrap import ( KCLVM_CLI_INSTALL_PATH_ENV_VAR, KCLVM_CLI_BIN_PATH_ENV_VAR, + KCLVM_CLI_USE_RELEASE_ENV_VAR, lib_full_name, install_kclvm, ) -from kcl_lib.bootstrap.artifact import lib_path +from kcl_lib.bootstrap.artifact import lib_path, LIB_ROOT from .spec_pb2 import * from ctypes import c_char_p, c_void_p from google.protobuf import message as _message @@ -103,6 +104,7 @@ def __init__(self): self._dir = tempfile.TemporaryDirectory() env_path = os.environ.get(KCLVM_CLI_BIN_PATH_ENV_VAR) env_install_path = os.environ.get(KCLVM_CLI_INSTALL_PATH_ENV_VAR) + env_use_release = os.environ.get(KCLVM_CLI_USE_RELEASE_ENV_VAR) if env_path: self.lib = ctypes.CDLL(os.path.join(env_path, lib_full_name())) elif env_install_path: @@ -110,6 +112,11 @@ def __init__(self): self.lib = ctypes.CDLL( os.path.join(env_install_path, "bin", lib_full_name()) ) + elif env_use_release: + # The release lib is located at "kcl_lib/lib/" + lib_path = LIB_ROOT.joinpath("lib") + os.environ[KCLVM_CLI_BIN_PATH_ENV_VAR] = str(lib_path) + self.lib = ctypes.CDLL(str(lib_path.joinpath(lib_full_name()))) else: # Install temp path. install_kclvm(self._dir.name) diff --git a/python/kcl_lib/bootstrap/__init__.py b/python/kcl_lib/bootstrap/__init__.py index d200b09f..9c669301 100644 --- a/python/kcl_lib/bootstrap/__init__.py +++ b/python/kcl_lib/bootstrap/__init__.py @@ -3,9 +3,10 @@ import platform from pathlib import Path -KCLVM_VERSION = "0.8.0-alpha.4" # You should replace this with actual version +KCLVM_VERSION = "0.8.0-alpha.5" # You should replace this with actual version KCLVM_CLI_BIN_PATH_ENV_VAR = "KCLVM_CLI_BIN_PATH" KCLVM_CLI_INSTALL_PATH_ENV_VAR = "KCLVM_CLI_INSTALL_PATH" +KCLVM_CLI_USE_RELEASE_ENV_VAR = "KCLVM_CLI_USE_RELEASE" LIB_NAME = "kclvm_cli_cdylib" diff --git a/python/kcl_lib/bootstrap/artifact.py b/python/kcl_lib/bootstrap/artifact.py index b530a45c..ea3245cb 100644 --- a/python/kcl_lib/bootstrap/artifact.py +++ b/python/kcl_lib/bootstrap/artifact.py @@ -19,14 +19,18 @@ def is_amd64_arch(): if sys.platform == "darwin": - if is_amd64_arch(): - with open(f"{LIB_ROOT}/lib/darwin-amd64/libkclvm_cli_cdylib.dylib", "rb") as f: - DARWIN_AMD64_CLI_LIB = f.read() - else: - with open(f"{LIB_ROOT}/lib/darwin-arm64/libkclvm_cli_cdylib.dylib", "rb") as f: - DARWIN_ARM64_CLI_LIB = f.read() def cli_lib(): + if is_amd64_arch(): + with open( + f"{LIB_ROOT}/lib/darwin-amd64/libkclvm_cli_cdylib.dylib", "rb" + ) as f: + DARWIN_AMD64_CLI_LIB = f.read() + else: + with open( + f"{LIB_ROOT}/lib/darwin-arm64/libkclvm_cli_cdylib.dylib", "rb" + ) as f: + DARWIN_ARM64_CLI_LIB = f.read() return DARWIN_AMD64_CLI_LIB if is_amd64_arch() else DARWIN_ARM64_CLI_LIB def lib_path() -> str: @@ -34,15 +38,18 @@ def lib_path() -> str: return str(LIB_ROOT.joinpath("lib").joinpath("darwin-amd64")) return str(LIB_ROOT.joinpath("lib").joinpath("darwin-arm64")) + def lib_name() -> str: + return "libkclvm_cli_cdylib.dylib" + elif sys.platform.startswith("linux"): - if is_amd64_arch(): - with open(f"{LIB_ROOT}/lib/linux-amd64/libkclvm_cli_cdylib.so", "rb") as f: - LINUX_AMD64_CLI_LIB = f.read() - else: - with open(f"{LIB_ROOT}/lib/linux-arm64/libkclvm_cli_cdylib.so", "rb") as f: - LINUX_ARM64_CLI_LIB = f.read() def cli_lib(): + if is_amd64_arch(): + with open(f"{LIB_ROOT}/lib/linux-amd64/libkclvm_cli_cdylib.so", "rb") as f: + LINUX_AMD64_CLI_LIB = f.read() + else: + with open(f"{LIB_ROOT}/lib/linux-arm64/libkclvm_cli_cdylib.so", "rb") as f: + LINUX_ARM64_CLI_LIB = f.read() return LINUX_AMD64_CLI_LIB if is_amd64_arch() else LINUX_ARM64_CLI_LIB def lib_path() -> str: @@ -50,22 +57,27 @@ def lib_path() -> str: return str(LIB_ROOT.joinpath("lib").joinpath("linux-amd64")) return str(LIB_ROOT.joinpath("lib").joinpath("linux-arm64")) + def lib_name() -> str: + return "libkclvm_cli_cdylib.so" + elif sys.platform == "win32": - if is_amd64_arch(): - with open(f"{LIB_ROOT}/lib/windows-amd64/kclvm_cli_cdylib.dll", "rb") as f: - WINDOWS_AMD64_CLI_LIB = f.read() - with open(f"{LIB_ROOT}/lib/windows-amd64/kclvm_cli_cdylib.lib", "rb") as f: - WINDOWS_AMD64_EXPORT_LIB = f.read() - else: - with open(f"{LIB_ROOT}/lib/windows-arm64/kclvm_cli_cdylib.dll", "rb") as f: - WINDOWS_ARM64_CLI_LIB = f.read() - with open(f"{LIB_ROOT}/lib/windows-arm64/kclvm_cli_cdylib.lib", "rb") as f: - WINDOWS_ARM64_EXPORT_LIB = f.read() def cli_lib(): + if is_amd64_arch(): + with open(f"{LIB_ROOT}/lib/windows-amd64/kclvm_cli_cdylib.dll", "rb") as f: + WINDOWS_AMD64_CLI_LIB = f.read() + else: + with open(f"{LIB_ROOT}/lib/windows-arm64/kclvm_cli_cdylib.dll", "rb") as f: + WINDOWS_ARM64_CLI_LIB = f.read() return WINDOWS_AMD64_CLI_LIB if is_amd64_arch() else WINDOWS_ARM64_CLI_LIB def export_lib(): + if is_amd64_arch(): + with open(f"{LIB_ROOT}/lib/windows-amd64/kclvm_cli_cdylib.lib", "rb") as f: + WINDOWS_AMD64_EXPORT_LIB = f.read() + else: + with open(f"{LIB_ROOT}/lib/windows-arm64/kclvm_cli_cdylib.lib", "rb") as f: + WINDOWS_ARM64_EXPORT_LIB = f.read() return WINDOWS_AMD64_EXPORT_LIB if is_amd64_arch() else WINDOWS_ARM64_EXPORT_LIB def lib_path() -> str: @@ -73,5 +85,11 @@ def lib_path() -> str: return str(LIB_ROOT.joinpath("lib").joinpath("windows-amd64")) return str(LIB_ROOT.joinpath("lib").joinpath("windows-arm64")) + def lib_name() -> str: + return "kclvm_cli_cdylib.dll" + + def export_lib_name() -> str: + return "kclvm_cli_cdylib.lib" + else: raise f"Unsupported platform {sys.platform}, expected win32, linux or darwin platform" diff --git a/python/setup.py b/python/setup.py index a3940d26..8038c83f 100644 --- a/python/setup.py +++ b/python/setup.py @@ -62,6 +62,9 @@ def is_amd64_arch(): def cli_lib(): return DARWIN_AMD64_CLI_LIB if is_amd64_arch() else DARWIN_ARM64_CLI_LIB + def lib_name(): + return "libkclvm_cli_cdylib.dylib" + elif PLATFORM.startswith("linux"): if is_amd64_arch(): LINUX_AMD64_CLI_LIB = "lib/linux-amd64/libkclvm_cli_cdylib.so" @@ -71,6 +74,9 @@ def cli_lib(): def cli_lib(): return LINUX_AMD64_CLI_LIB if is_amd64_arch() else LINUX_ARM64_CLI_LIB + def lib_name(): + return "libkclvm_cli_cdylib.so" + elif PLATFORM == "win32": if is_amd64_arch(): WINDOWS_AMD64_CLI_LIB = "lib/windows-amd64/kclvm_cli_cdylib.dll" @@ -85,6 +91,12 @@ def cli_lib(): def export_lib(): return WINDOWS_AMD64_EXPORT_LIB if is_amd64_arch() else WINDOWS_ARM64_EXPORT_LIB + def lib_name(): + return "kclvm_cli_cdylib.dll" + + def export_lib_name(): + return "kclvm_cli_cdylib.lib" + else: raise f"Unsupported platform {PLATFORM}, expected win32, linux or darwin platform" @@ -95,14 +107,15 @@ def copyfile(src: pathlib.Path, dst: pathlib.Path) -> str: return str(dst.relative_to(pathlib.Path(__file__).parent)) +# Copy libs to the kcl_lib/lib folder def copy_libs(): source_dir = pathlib.Path(__file__).parent.parent - target_dir = pathlib.Path(__file__).parent.joinpath("kcl_lib") + target_dir = pathlib.Path(__file__).parent.joinpath("kcl_lib").joinpath("lib") data_files = [] - data_files.append(copyfile(source_dir / cli_lib(), target_dir / cli_lib())) + data_files.append(copyfile(source_dir / cli_lib(), target_dir / lib_name())) if PLATFORM in ["windows"]: data_files.append( - copyfile(source_dir / export_lib(), target_dir / export_lib()) + copyfile(source_dir / export_lib(), target_dir / export_lib_name()) ) return data_files @@ -121,7 +134,7 @@ def copy_libs(): setup( name="kcl_lib", author="KCL Authors", - version="0.8.0-alpha.4", + version="0.8.0-alpha.5", license="Apache License 2.0", python_requires=">=3.7", description="KCL Artifact Library for Python",