Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
33 changes: 14 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,29 @@ jobs:
"hdfs_3_3",
]

# We set JAVA_HOME, JAVA_HOME_8_X64 and JAVA_HOME_8_ARM64,
# to ensure compilation works out of the box for all targets
# A user can manually specify JAVA_HOME to use their own distribution
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
id: setup_java
with:
distribution: 'temurin'
distribution: 'corretto'
java-version: '8'

# Add jvm.dll in PATH to make sure windows can find it.
- name: Update path for windows
if: matrix.os == 'windows-latest'
run: |
echo "${{ steps.setup_java.outputs.path }}\lib" >> $GITHUB_PATH
echo "${{ steps.setup_java.outputs.path }}\jre\bin\server" >> $GITHUB_PATH
echo "LIB=${LIB};${{ steps.setup_java.outputs.path }}\lib;${{ steps.setup_java.outputs.path }}\jre\bin\server" >> $GITHUB_ENV

# Add libjvm.dylib in RPATH to make sure macos can find it.
- name: Update path for macos
if: matrix.os == 'macos-latest'
run: |
mkdir -p ~/lib
ln -s ${{ steps.setup_java.outputs.path }}/jre/lib/server/libjvm.dylib ~/lib/

- name: Build
run: cargo build --features ${{ matrix.feature }}
run: cargo build --features ${{ matrix.feature }},vendored
env:
JAVA_HOME: ""
JAVA_HOME_8_X64: ""
JAVA_HOME_8_ARM64: ""

- name: Test
run: cargo test --features ${{ matrix.feature }} -- --nocapture
run: cargo test --features ${{ matrix.feature }},vendored -- --nocapture
env:
RUST_LOG: DEBUG
RUST_BACKTRACE: full
LD_LIBRARY_PATH: ${{ env.JAVA_HOME }}/lib/server:${{ env.JAVA_HOME }}/lib/amd64/server:${{ env.JAVA_HOME }}/jre/lib/server:${{ env.JAVA_HOME }}/jre/lib/amd64/server
JAVA_HOME: ""
JAVA_HOME_8_X64: ""
JAVA_HOME_8_ARM64: ""
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ hdfs_3_1 = ["hdfs_3_0"]
hdfs_3_2 = ["hdfs_3_1"]
hdfs_3_3 = ["hdfs_3_2"]

vendored = []
vendored = ["java-locator/locate-jdk-only"] # JRE is not enough for building, we need the JDK

[build-dependencies]
cc = "1"
Expand Down
23 changes: 19 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ fn find_jvm() -> Result<()> {
println!("cargo:rustc-link-lib=jvm");
println!("cargo:rustc-link-search=native={jvm_path}");

// Add JVM to rpath
println!("cargo:rustc-link-arg=-Wl,-rpath,{jvm_path}");
Copy link
Author

@EmilyFlarionIO EmilyFlarionIO Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust specs ensures this does not propagate upwards(unless it is a cdylib, which will then have this in its RPATH), so this is not a security concern, only relevant for tests and/or binaries from this crate.

It is also why we export the used path as metadata below, if another crate does need it, it can use it directly


// Export the used JVM_PATH as metadata, in case a crate needs it in order to link
println!("cargo:metadata=JVM_PATH={jvm_path}");

// Add jvm.lib into search path for windows.
if cfg!(windows) {
if let Ok(jvm_lib_path) = java_locator::locate_file("jvm.lib") {
println!("cargo:rustc-link-search=native={jvm_lib_path}");
}
#[cfg(windows)]
if let Ok(jvm_lib_path) = java_locator::locate_file("jvm.lib") {
println!("cargo:rustc-link-search=native={jvm_lib_path}");
}

Ok(())
Expand Down Expand Up @@ -76,7 +81,11 @@ fn build_libhdfs() -> Result<()> {

let mut builder = cc::Build::new();
builder.warnings(false);

// This flag does not work on windows, just throws warnings
#[cfg(not(windows))]
builder.static_flag(true);

builder.static_crt(true);

// Ignore all warnings from cc as we don't care about code written by Apache Hadoop.
Expand Down Expand Up @@ -211,6 +220,12 @@ fn build_libhdfs() -> Result<()> {
}
}

#[cfg(not(feature = "vendored"))]
{
println!("cargo:warning=Building libhdfs from source as a fallback, \
if you are encountering issues with missing headers on JDK8, consider enabling the `vendored` feature.");
}

builder.compile("hdfs");
Ok(())
}
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ pub use hdfs_2_3::*;
#[cfg(feature = "hdfs_2_4")]
mod hdfs_2_4;
#[cfg(feature = "hdfs_2_4")]
#[allow(unused_imports)]
pub use hdfs_2_4::*;
#[cfg(feature = "hdfs_2_5")]
mod hdfs_2_5;
#[cfg(feature = "hdfs_2_5")]
#[allow(unused_imports)]
pub use hdfs_2_5::*;
#[cfg(feature = "hdfs_2_6")]
mod hdfs_2_6;
Expand All @@ -77,6 +79,7 @@ pub use hdfs_2_7::*;
#[cfg(feature = "hdfs_2_8")]
mod hdfs_2_8;
#[cfg(feature = "hdfs_2_8")]
#[allow(unused_imports)]
pub use hdfs_2_8::*;
#[cfg(feature = "hdfs_2_9")]
mod hdfs_2_9;
Expand All @@ -85,6 +88,7 @@ pub use hdfs_2_9::*;
#[cfg(feature = "hdfs_2_10")]
mod hdfs_2_10;
#[cfg(feature = "hdfs_2_10")]
#[allow(unused_imports)]
pub use hdfs_2_10::*;
#[cfg(feature = "hdfs_3_0")]
mod hdfs_3_0;
Expand All @@ -93,10 +97,12 @@ pub use hdfs_3_0::*;
#[cfg(feature = "hdfs_3_1")]
mod hdfs_3_1;
#[cfg(feature = "hdfs_3_1")]
#[allow(unused_imports)]
pub use hdfs_3_1::*;
#[cfg(feature = "hdfs_3_2")]
mod hdfs_3_2;
#[cfg(feature = "hdfs_3_2")]
#[allow(unused_imports)]
pub use hdfs_3_2::*;
#[cfg(feature = "hdfs_3_3")]
mod hdfs_3_3;
Expand Down