Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(bindings/java): support explicit cargo build target #3168

Merged
merged 5 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/bindings_java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@ jobs:
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
distribution: 'zulu'
java-version: '8'
cache: 'maven'
- name: Install Protoc
uses: arduino/setup-protoc@v2
with:
version: "23.4"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and test
working-directory: bindings/java
# `mvn install` and `mvn artifact:compare` are required to verify reproducible builds:
Expand Down
9 changes: 9 additions & 0 deletions bindings/java/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[target.x86_64-unknown-linux-musl]
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
rustflags = [
"-C", "target-feature=-crt-static",
]

[target.aarch64-unknown-linux-musl]
rustflags = [
"-C", "target-feature=-crt-static",
]
3 changes: 3 additions & 0 deletions bindings/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<!-- customized properties -->
<cargo-build.profile>dev</cargo-build.profile>
<cargo-build.features>default</cargo-build.features>
<cargo-build.target/> <!-- override cargo build target; e.g., use musl instead -->
<jni.classifier>${os.detected.classifier}</jni.classifier>

<!-- library dependencies -->
Expand Down Expand Up @@ -177,6 +178,8 @@
<argument>${project.basedir}/tools/build.py</argument>
<argument>--classifier</argument>
<argument>${jni.classifier}</argument>
<argument>--target</argument>
<argument>${cargo-build.target}</argument>
<argument>--profile</argument>
<argument>${cargo-build.profile}</argument>
<argument>--features</argument>
Expand Down
18 changes: 11 additions & 7 deletions bindings/java/tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.


from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, BooleanOptionalAction
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from pathlib import Path
import shutil
import subprocess
Expand Down Expand Up @@ -52,6 +52,7 @@ def get_cargo_artifact_name(classifier: str) -> str:

parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('--classifier', type=str, required=True)
parser.add_argument('--target', type=str, default='')
parser.add_argument('--profile', type=str, default='dev')
parser.add_argument('--features', type=str, default='default')
args = parser.parse_args()
Expand All @@ -61,12 +62,15 @@ def get_cargo_artifact_name(classifier: str) -> str:
if args.features:
cmd += ['--features', args.features]

target = classifier_to_target(args.classifier)
if target:
command = ['rustup', 'target', 'add', target]
print('$ ' + subprocess.list2cmdline(command))
subprocess.run(command, cwd=basedir, check=True)
cmd += ['--target', target]
if args.target:
target = args.target
else:
target = classifier_to_target(args.classifier)

command = ['rustup', 'target', 'add', target]
print('$ ' + subprocess.list2cmdline(command))
subprocess.run(command, cwd=basedir, check=True)
cmd += ['--target', target]

output = basedir / 'target' / 'bindings'
Path(output).mkdir(exist_ok=True, parents=True)
Expand Down