mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
Java publishing (#151)
* bindings/java: Add prefix to native methods * bindings/java: Add javadocs and missing methods to Engine * Setup publishing uber-JAR via GitHub workflow * bindings/java: Update README * bindings/java: Improve native library loading from JAR * bindings/java: Fix usage of `working-directory` * bindings/java: Pass required `distribution` parameter to `actions/setup-java@v4` * bindings/java: Use Corretto distribution This is because Microsoft doesn't provide JDK8, see https://learn.microsoft.com/en-us/java/openjdk/download#openjdk-8. * bindings/java: Install GCC toolchain for `aarch64-unknown-linux-gnu` * bindings/java: Upload artifacts with different names from each step * bindings/java: Upload built JARs to GitHub
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
#
|
||||
# This script adapted from:
|
||||
# https://github.com/apache/opendal/blob/93e5f65bbf30df2fed4bdd95bb0685c73c6418c2/bindings/java/tools/build.py
|
||||
|
||||
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
def classifier_to_target(classifier: str) -> str:
|
||||
if classifier == 'osx-aarch_64':
|
||||
return 'aarch64-apple-darwin'
|
||||
if classifier == 'osx-x86_64':
|
||||
return 'x86_64-apple-darwin'
|
||||
if classifier == 'linux-aarch_64':
|
||||
return 'aarch64-unknown-linux-gnu'
|
||||
if classifier == 'linux-x86_64':
|
||||
return 'x86_64-unknown-linux-gnu'
|
||||
if classifier == 'windows-x86_64':
|
||||
return 'x86_64-pc-windows-msvc'
|
||||
raise Exception(f'Unsupported classifier: {classifier}')
|
||||
|
||||
def get_cargo_artifact_name(classifier: str) -> str:
|
||||
if classifier.startswith('osx'):
|
||||
return 'libregorus_java.dylib'
|
||||
if classifier.startswith('linux'):
|
||||
return 'libregorus_java.so'
|
||||
if classifier.startswith('windows'):
|
||||
return 'regorus_java.dll'
|
||||
raise Exception(f'Unsupported classifier: {classifier}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
basedir = Path(__file__).parent.parent
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('--classifier', type=str, required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
target = classifier_to_target(args.classifier)
|
||||
|
||||
# Setup target.
|
||||
command = ['rustup', 'target', 'add', target]
|
||||
print('$ ' + subprocess.list2cmdline(command))
|
||||
subprocess.run(command, cwd=basedir, check=True)
|
||||
|
||||
cmd = ['cargo', 'build', '--target', target]
|
||||
|
||||
output = basedir / 'target' / 'bindings'
|
||||
Path(output).mkdir(exist_ok=True, parents=True)
|
||||
cmd += ['--target-dir', str(output)]
|
||||
|
||||
print('$ ' + subprocess.list2cmdline(cmd))
|
||||
subprocess.run(cmd, cwd=basedir, check=True)
|
||||
|
||||
# History reason of cargo profiles.
|
||||
profile = 'debug'
|
||||
artifact = get_cargo_artifact_name(args.classifier)
|
||||
src = output / target / profile / artifact
|
||||
dst = basedir / 'target' / 'classes' / 'native' / args.classifier / artifact
|
||||
dst.parent.mkdir(exist_ok=True, parents=True)
|
||||
shutil.copy2(src, dst)
|
||||
17
bindings/java/tools/testbuild.py
Normal file
17
bindings/java/tools/testbuild.py
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
#
|
||||
# Builds Regorus Java to use in Java tests. See `pom.xml`.
|
||||
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
if __name__ == "__main__":
|
||||
basedir = Path(__file__).parent.parent
|
||||
|
||||
output = basedir / "target"
|
||||
Path(output).mkdir(exist_ok=True, parents=True)
|
||||
cmd = ["cargo", "build", "--target-dir", str(output)]
|
||||
print("$ " + subprocess.list2cmdline(cmd))
|
||||
subprocess.run(cmd, cwd=basedir, check=True)
|
||||
Reference in New Issue
Block a user