diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 052e1bd..b92086e 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -4,9 +4,11 @@ on: push: branches: - master + - develop pull_request: branches: - master + - develop jobs: build-randomx: runs-on: ${{ matrix.os }} @@ -18,25 +20,25 @@ jobs: # Linux - x86_64 - os: ubuntu-latest arch: x86_64 - cmake_args: '-DARCH=x86_64 -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"' + cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"' artifact_name: 'librandomx_linux_x86_64.so' output_lib: 'librandomx_linux_x86_64.so' # macOS - x86_64 - os: macos-latest arch: x86_64 - cmake_args: '-DARCH=x86_64 -DBUILD_SHARED_LIBS=ON' + cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON' artifact_name: 'librandomx_macos_x86_64.dylib' output_lib: 'librandomx_macos_x86_64.dylib' # macOS - aarch64 - os: macos-latest arch: aarch64 - cmake_args: '-DARCH=arm64 -DBUILD_SHARED_LIBS=ON' + cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON' artifact_name: 'librandomx_macos_aarch64.dylib' output_lib: 'librandomx_macos_aarch64.dylib' # Windows - x86_64 - os: windows-latest arch: x86_64 - cmake_args: '-G "MinGW Makefiles" -DARCH=native -DBUILD_SHARED_LIBS=ON' + cmake_args: '-G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON' artifact_name: 'librandomx_windows_x86_64.dll' output_lib: 'librandomx_windows_x86_64.dll' exclude: @@ -74,7 +76,7 @@ jobs: cd randomx mkdir build && cd build cmake .. ${{ matrix.cmake_args }} - make + make -j4 mkdir -p ../../src/main/resources/native if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then cp *.so ../../src/main/resources/native/${{ matrix.output_lib }} @@ -125,57 +127,57 @@ jobs: runs-on: ubuntu-latest needs: build-java steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install gh CLI - run: sudo apt-get install -y gh - - - name: Extract Version from pom.xml - id: extract_version - run: | - VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) - echo "VERSION=$VERSION" >> $GITHUB_ENV - echo "Extracted version: $VERSION" - - - name: Download JAR Artifact - uses: actions/download-artifact@v4 - with: - name: xdagj-native-randomx-jar - path: target/ - - - name: Find Main JAR File - id: find_jar - run: | - JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" | head -n 1) - if [ -z "$JAR_FILE" ]; then - echo "Error: No main JAR file found!" - exit 1 - fi - echo "Found JAR file: $JAR_FILE" - echo "jar_file=$JAR_FILE" >> $GITHUB_ENV - - - name: Generate Release Notes - run: | - echo "### Changelog" > RELEASE_NOTES.md - echo "" >> RELEASE_NOTES.md - echo "$(git log --pretty=format:"* %s (%h)" --no-merges $(git rev-list --tags --max-count=1)..HEAD)" >> RELEASE_NOTES.md - echo "" >> RELEASE_NOTES.md - echo "### Additional Notes" >> RELEASE_NOTES.md - echo "- Build improvements." >> RELEASE_NOTES.md - echo "- Known issues: None." >> RELEASE_NOTES.md - - - name: Create Release using gh CLI - run: | - gh release create "v${{ env.VERSION }}" --title "xdagj-native-randomx v${{ env.VERSION }}" --notes-file RELEASE_NOTES.md - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - - - name: Rename output file - run: mv "target/xdagj-native-randomx-${{ env.VERSION }}.jar" "target/xdagj-native-randomx.jar" - - - name: Upload JAR using gh CLI - run: | - gh release upload "v${{ env.VERSION }}" target/xdagj-native-randomx.jar --clobber - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install gh CLI + run: sudo apt-get install -y gh + + - name: Extract Version from pom.xml + id: extract_version + run: | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "Extracted version: $VERSION" + + - name: Download JAR Artifact + uses: actions/download-artifact@v4 + with: + name: xdagj-native-randomx-jar + path: target/ + + - name: Find Main JAR File + id: find_jar + run: | + JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" | head -n 1) + if [ -z "$JAR_FILE" ]; then + echo "Error: No main JAR file found!" + exit 1 + fi + echo "Found JAR file: $JAR_FILE" + echo "jar_file=$JAR_FILE" >> $GITHUB_ENV + + - name: Generate Release Notes + run: | + echo "### Changelog" > RELEASE_NOTES.md + echo "" >> RELEASE_NOTES.md + echo "$(git log --pretty=format:"* %s (%h)" --no-merges $(git rev-list --tags --max-count=1)..HEAD)" >> RELEASE_NOTES.md + echo "" >> RELEASE_NOTES.md + echo "### Additional Notes" >> RELEASE_NOTES.md + echo "- Build improvements." >> RELEASE_NOTES.md + echo "- Known issues: None." >> RELEASE_NOTES.md + + - name: Create Release using gh CLI + run: | + gh release create "v${{ env.VERSION }}" --title "xdagj-native-randomx v${{ env.VERSION }}" --notes-file RELEASE_NOTES.md + env: + GH_TOKEN: ${{ github.token }} # Use the token automatically generated by GitHub + + - name: Rename output file + run: mv "target/xdagj-native-randomx-${{ env.VERSION }}.jar" "target/xdagj-native-randomx.jar" + + - name: Upload JAR using gh CLI + run: | + gh release upload "v${{ env.VERSION }}" target/xdagj-native-randomx.jar --clobber + env: + GH_TOKEN: ${{ github.token }} # Use the token automatically generated by GitHub diff --git a/README.md b/README.md index 7ee0d80..e773903 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Compile and copy the appropriate shared library for your platform: ```bash cd randomx mkdir build && cd build -cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON +cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC" make -j4 cp -i librandomx.so ../../src/main/resources/native/librandomx_linux_x86_64.so ``` @@ -175,9 +175,9 @@ public class Example { | Benchmark | Mode | Cnt | Score | Error | Units | |:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:| | RandomXBenchmark.lightBatch | thrpt | | 328.736 | | ops/s | -| RandomXBenchmark.lightNoBatch | thrpt | | 325.383 | | s/op | -| RandomXBenchmark.miningBatch | thrpt | | 2777.939 | | s/op | -| RandomXBenchmark.miningNoBatch | thrpt | | 2817.811 | | s/op | +| RandomXBenchmark.lightNoBatch | thrpt | | 325.383 | | ops/s | +| RandomXBenchmark.miningBatch | thrpt | | 2777.939 | | ops/s | +| RandomXBenchmark.miningNoBatch | thrpt | | 2817.811 | | ops/s | --- @@ -194,9 +194,9 @@ JIT flag will cause jvm to crash in MacOS | Benchmark | Mode | Cnt | Score | Error | Units | |:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:| | RandomXBenchmark.lightBatch | thrpt | | 32.864 | | ops/s | -| RandomXBenchmark.lightNoBatch | thrpt | | 33.683 | | s/op | -| RandomXBenchmark.miningBatch | thrpt | | 554.966 | | s/op | -| RandomXBenchmark.miningNoBatch | thrpt | | 570.060 | | s/op | +| RandomXBenchmark.lightNoBatch | thrpt | | 33.683 | | ops/s | +| RandomXBenchmark.miningBatch | thrpt | | 554.966 | | ops/s | +| RandomXBenchmark.miningNoBatch | thrpt | | 570.060 | | ops/s | --- @@ -206,4 +206,4 @@ We welcome contributions to improve the project! Please feel free to submit issu For discussions or questions, contact the [xdagj community](https://github.com/XDagger/xdagj). ---- \ No newline at end of file +--- diff --git a/src/main/java/io/xdag/crypto/randomx/RandomXJNALoader.java b/src/main/java/io/xdag/crypto/randomx/RandomXJNALoader.java index 259a5d4..f0d527f 100644 --- a/src/main/java/io/xdag/crypto/randomx/RandomXJNALoader.java +++ b/src/main/java/io/xdag/crypto/randomx/RandomXJNALoader.java @@ -77,7 +77,13 @@ public static RandomXJNA getInstance() { synchronized (LOCK) { result = instance; if (result == null) { - instance = result = Native.load("randomx", RandomXJNA.class); + String osName = System.getProperty("os.name").toLowerCase(); + if (osName.contains("win")) { + String libFilePath = "native/librandomx_windows_x86_64.dll"; + instance = result = Native.load(libFilePath, RandomXJNA.class); + } else { + instance = result = Native.load("randomx", RandomXJNA.class); + } } } } @@ -119,7 +125,9 @@ public static void loadLibrary(String libraryName) { */ private static String getLibraryFileName(String libraryName, String os, String arch) { if (os.contains("win")) { - return String.format("native/%s_windows_%s.dll", libraryName, arch); + if (StringUtils.containsAny(arch, "amd64", "x86_64")) { + return String.format("native/%s_windows_x86_64.dll", libraryName); + } } else if (os.contains("mac")) { return String.format("native/%s_macos_%s.dylib", libraryName, arch); } else if (StringUtils.contains(os, "linux")) { diff --git a/src/main/resources/native/librandomx_linux_x86_64.so b/src/main/resources/native/librandomx_linux_x86_64.so index ffc9fed..62637c6 100644 Binary files a/src/main/resources/native/librandomx_linux_x86_64.so and b/src/main/resources/native/librandomx_linux_x86_64.so differ diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXBenchmark.java b/src/test/java/io/xdag/crypto/randomx/RandomXBenchmark.java index e08ca49..b889fe0 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXBenchmark.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXBenchmark.java @@ -181,4 +181,4 @@ public static void main(String[] args) throws Exception { new Runner(opt).run(); } -} \ No newline at end of file +} diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXCacheTest.java b/src/test/java/io/xdag/crypto/randomx/RandomXCacheTest.java index c511b85..d810875 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXCacheTest.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXCacheTest.java @@ -62,4 +62,4 @@ public void testInit() { } // Cache is automatically released here. } -} +} \ No newline at end of file diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXDatasetTest.java b/src/test/java/io/xdag/crypto/randomx/RandomXDatasetTest.java index 4e5e89b..69eb8fc 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXDatasetTest.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXDatasetTest.java @@ -72,4 +72,4 @@ void testInitialization() { } } -} \ No newline at end of file +} diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXJNALoaderTest.java b/src/test/java/io/xdag/crypto/randomx/RandomXJNALoaderTest.java index aedd768..509a52d 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXJNALoaderTest.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXJNALoaderTest.java @@ -40,4 +40,5 @@ public class RandomXJNALoaderTest { public void testLibraryLoading() { assertNotNull(RandomXJNALoader.getInstance(), "RandomXJNA instance should not be null."); } + } \ No newline at end of file diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXTemplateTest.java b/src/test/java/io/xdag/crypto/randomx/RandomXTemplateTest.java index e1b7261..01d825c 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXTemplateTest.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXTemplateTest.java @@ -117,4 +117,4 @@ public void testChangeKey() { assertEquals("3910d7b054df9ba920e2f7e103aa2c1fc4597b13d1793f1ab08c1c9c922709c0", hex.formatHex(hash)); } -} \ No newline at end of file +} diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXTests.java b/src/test/java/io/xdag/crypto/randomx/RandomXTests.java index 9527051..921d8a8 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXTests.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXTests.java @@ -140,4 +140,4 @@ void testBatchHash() { assertEquals("c36d4ed4191e617309867ed66a443be4075014e2b061bcdaf9ce7b721d2b77a8", hex.formatHex(hash3)); } -} +} \ No newline at end of file diff --git a/src/test/java/io/xdag/crypto/randomx/RandomXVMTest.java b/src/test/java/io/xdag/crypto/randomx/RandomXVMTest.java index 30971f1..f15ed6e 100644 --- a/src/test/java/io/xdag/crypto/randomx/RandomXVMTest.java +++ b/src/test/java/io/xdag/crypto/randomx/RandomXVMTest.java @@ -60,4 +60,5 @@ public void testVMHashCalculation() { assertEquals(32, output.length, "Output size should be 32 bytes."); } } + } \ No newline at end of file