Skip to content

Commit

Permalink
Merge pull request #43 from kcl-lang/fix-kcl-lib-release-folder
Browse files Browse the repository at this point in the history
fix: kcl lib release folder
  • Loading branch information
Peefy authored Feb 26, 2024
2 parents 9fbba3e + f8fc748 commit ec71c93
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kcl</groupId>
<artifactId>kcl-lib</artifactId>
<version>0.8.0-alpha.4</version>
<version>0.8.0-alpha.5</version>
<name>KCL Arifact Library for Java</name>
<description>
KCL is an open-source constraint-based record and functional language mainly
Expand Down
9 changes: 8 additions & 1 deletion python/kcl_lib/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -103,13 +104,19 @@ 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:
install_kclvm(env_install_path)
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)
Expand Down
3 changes: 2 additions & 1 deletion python/kcl_lib/bootstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
62 changes: 40 additions & 22 deletions python/kcl_lib/bootstrap/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,77 @@ 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:
if is_amd64_arch():
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:
if is_amd64_arch():
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:
if is_amd64_arch():
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"
21 changes: 17 additions & 4 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"

Expand All @@ -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

Expand All @@ -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",
Expand Down

0 comments on commit ec71c93

Please sign in to comment.