Skip to content
Merged
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
89 changes: 71 additions & 18 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ jobs:
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: '-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
Expand All @@ -49,6 +43,9 @@ jobs:
arch: amd64
- os: macos-latest
arch: amd64
# Exclude macOS-aarch64 from GitHub Actions build
- os: macos-latest
arch: aarch64
- os: windows-latest
arch: aarch64
- os: windows-latest
Expand All @@ -75,15 +72,34 @@ jobs:
run: |
cd randomx
mkdir build && cd build

echo "Configuring for native compilation"
cmake .. ${{ matrix.cmake_args }}

make -j4
mkdir -p ../../src/main/resources/native

# Platform-specific copy commands with verification
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
cp *.so ../../src/main/resources/native/${{ matrix.output_lib }}
cp -v librandomx.so ../../src/main/resources/native/${{ matrix.output_lib }}
ls -la ../../src/main/resources/native/
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
cp *.dylib ../../src/main/resources/native/${{ matrix.output_lib }}
cp -v librandomx.dylib ../../src/main/resources/native/${{ matrix.output_lib }}
ls -la ../../src/main/resources/native/
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp *.dll ../../src/main/resources/native/${{ matrix.output_lib }}
cp -v librandomx.dll ../../src/main/resources/native/${{ matrix.output_lib }}
ls -la ../../src/main/resources/native/
fi
shell: bash

- name: Verify library file
run: |
echo "Verifying library file in native resources directory"
if [ -f "src/main/resources/native/${{ matrix.output_lib }}" ]; then
echo "✅ Library file ${{ matrix.output_lib }} exists"
else
echo "❌ Library file ${{ matrix.output_lib }} is missing"
exit 1
fi
shell: bash

Expand All @@ -100,12 +116,29 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Download Dynamic Link Library Artifacts
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: src/main/resources/native/
pattern: librandomx-*
- run: ls src/main/resources/native/
merge-multiple: true

- name: Check for Apple Silicon Library
run: |
echo "Checking for macOS ARM64 library (should be precompiled locally)"
if [ -f "src/main/resources/native/librandomx_macos_aarch64.dylib" ]; then
echo "✅ Found precompiled Apple Silicon library"
else
echo "⚠️ WARNING: Apple Silicon library (librandomx_macos_aarch64.dylib) not found!"
echo "⚠️ Please compile this library locally on an Apple Silicon Mac and commit it to the repository."
echo "⚠️ Build will continue but the final JAR will not support Apple Silicon Macs."
fi
shell: bash

- name: List downloaded artifacts
run: |
echo "Contents of native resources directory:"
ls -la src/main/resources/native/
shell: bash

- name: Set up JDK
uses: actions/setup-java@v4
Expand All @@ -126,6 +159,8 @@ jobs:
release:
runs-on: ubuntu-latest
needs: build-java
# Only run release job on master branch
if: github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -149,34 +184,52 @@ jobs:
- name: Find Main JAR File
id: find_jar
run: |
JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" | head -n 1)
JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.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
# Also set the JAR filename without path for easier use
JAR_BASENAME=$(basename "$JAR_FILE")
echo "jar_basename=$JAR_BASENAME" >> $GITHUB_ENV

- name: Generate Release Notes
if: github.ref == 'refs/heads/master' # Only on master branch
run: |
echo "### Changelog" > RELEASE_NOTES.md
echo "# xdagj-native-randomx v${{ env.VERSION }}" > 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 "## Changes" >> RELEASE_NOTES.md
echo "- Updated RandomX native libraries" >> RELEASE_NOTES.md
echo "- Improved build process" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "### Additional Notes" >> RELEASE_NOTES.md
echo "- Build improvements." >> RELEASE_NOTES.md
echo "## Native libraries included" >> RELEASE_NOTES.md
echo "- Linux: x86_64" >> RELEASE_NOTES.md
echo "- Windows: x86_64" >> RELEASE_NOTES.md
echo "- macOS: x86_64, aarch64 (Apple Silicon)" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "## System requirements" >> RELEASE_NOTES.md
echo "- JDK 17 or later" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "## Known issues" >> RELEASE_NOTES.md
echo "- Known issues: None." >> RELEASE_NOTES.md

- name: Create Release using gh CLI
if: github.ref == 'refs/heads/master' # Only on master branch
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"
run: |
echo "Original JAR path: ${{ env.jar_file }}"
cp "${{ env.jar_file }}" "target/xdagj-native-randomx.jar"
echo "✅ Renamed JAR file created at target/xdagj-native-randomx.jar"

- name: Upload JAR using gh CLI
if: github.ref == 'refs/heads/master' # Only on master branch
run: |
gh release upload "v${{ env.VERSION }}" target/xdagj-native-randomx.jar --clobber
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/

.DS_Store
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Support the project with XDAG donations:

- **JDK**: v17 or later
- **Maven**: v3.9.9 or later
- **CMake**: v3.5 or later
- **GCC/Compiler**: GCC v4.8 or later (v7+ recommended for best performance)

### **2. Build Steps**

Expand Down Expand Up @@ -73,12 +75,19 @@ make -j4
cp -i librandomx.dylib ../../src/main/resources/native/librandomx_macos_x86_64.dylib
```

##### **macOS aarch64**
##### **macOS aarch64 (Apple Silicon)**
For Apple Silicon Macs (M1, M2, M3), use the provided script:
```bash
# Run from the project root
./scripts/build-macos-arm64.sh
```

Or manually:
```bash
cd randomx
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON
make -j4
make -j$(sysctl -n hw.ncpu)
cp -i librandomx.dylib ../../src/main/resources/native/librandomx_macos_aarch64.dylib
```

Expand All @@ -90,6 +99,7 @@ cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_S
make -j4
cp -i randomx.dll ../../src/main/resources/native/librandomx_windows_x86_64.dll
```
You can also compile using Visual Studio, as the official RandomX repository provides solution files.

#### **2.3 Compile Java Library**
```bash
Expand Down Expand Up @@ -204,6 +214,18 @@ JIT flag will cause jvm to crash in MacOS

We welcome contributions to improve the project! Please feel free to submit issues or pull requests.

### **Contributing to the library**

If you're submitting changes that might affect the native libraries:

1. For platform-specific changes, compile the native library for your platform:
* Linux x86_64, macOS x86_64, or Windows x86_64: Follow the compilation steps above.
* macOS aarch64 (Apple Silicon): Must be compiled on an Apple Silicon Mac using provided script.

2. Commit both your code changes and the updated native library files.

3. GitHub Actions will build for other platforms and generate a complete multi-platform JAR.

For discussions or questions, contact the [xdagj community](https://github.com/XDagger/xdagj).

---
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.xdag</groupId>
<artifactId>xdagj-native-randomx</artifactId>
<version>0.2.1</version>
<version>0.2.2</version>

<name>xdagj-native-randomx</name>
<description>A Java RandomX Library For XDAGJ</description>
Expand All @@ -22,10 +22,10 @@

<!-- Dependency versions -->
<commons-lang3.version>3.17.0</commons-lang3.version>
<jna.version>5.15.0</jna.version>
<lombok.version>1.18.34</lombok.version>
<slf4j.version>2.0.16</slf4j.version>
<junit.version>5.10.3</junit.version>
<jna.version>5.17.0</jna.version>
<lombok.version>1.18.38</lombok.version>
<slf4j.version>2.0.17</slf4j.version>
<junit.version>5.12.2</junit.version>
<jmh.version>1.37</jmh.version>

<!-- Plugin versions -->
Expand Down
2 changes: 1 addition & 1 deletion randomx
Submodule randomx updated 1 files
+4 −1 src/virtual_memory.c
37 changes: 37 additions & 0 deletions scripts/build-macos-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Script to build RandomX for Apple Silicon (M series chips)
# This script should be run on an Apple Silicon Mac

# Check if running on ARM Mac
if [[ $(uname -m) != "arm64" ]]; then
echo "❌ This script must be run on an Apple Silicon Mac (M1/M2/M3)"
exit 1
fi

echo "🔍 Building RandomX library for Apple Silicon (ARM64)..."

# Navigate to randomx directory
cd "$(dirname "$0")/../randomx" || exit 1

# Create build directory if it doesn't exist
mkdir -p build
cd build || exit 1

echo "🔧 Running CMake..."
cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON

echo "🔨 Compiling RandomX..."
make -j$(sysctl -n hw.ncpu)

# Create native resources directory if it doesn't exist
mkdir -p ../../src/main/resources/native

echo "📦 Copying library to resources directory..."
cp -vf librandomx.dylib ../../src/main/resources/native/librandomx_macos_aarch64.dylib

echo "✅ Build complete!"
echo "Library location: src/main/resources/native/librandomx_macos_aarch64.dylib"
echo ""
echo "Please commit this file to your repository before pushing to GitHub."
echo "This will allow GitHub Actions to package it with the other platform libraries."
Binary file modified src/main/resources/native/librandomx_macos_aarch64.dylib
100644 → 100755
Binary file not shown.
Loading