Skip to content

Commit a350a16

Browse files
authored
upgrade to 0.2.2
upgrade to 0.2.2
2 parents bd8bd23 + ca47c7e commit a350a16

25 files changed

+1538
-866
lines changed

.github/workflows/build-and-release.yml

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ jobs:
2929
cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON'
3030
artifact_name: 'librandomx_macos_x86_64.dylib'
3131
output_lib: 'librandomx_macos_x86_64.dylib'
32-
# macOS - aarch64
33-
- os: macos-latest
34-
arch: aarch64
35-
cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON'
36-
artifact_name: 'librandomx_macos_aarch64.dylib'
37-
output_lib: 'librandomx_macos_aarch64.dylib'
3832
# Windows - x86_64
3933
- os: windows-latest
4034
arch: x86_64
@@ -49,6 +43,9 @@ jobs:
4943
arch: amd64
5044
- os: macos-latest
5145
arch: amd64
46+
# Exclude macOS-aarch64 from GitHub Actions build
47+
- os: macos-latest
48+
arch: aarch64
5249
- os: windows-latest
5350
arch: aarch64
5451
- os: windows-latest
@@ -75,15 +72,34 @@ jobs:
7572
run: |
7673
cd randomx
7774
mkdir build && cd build
75+
76+
echo "Configuring for native compilation"
7877
cmake .. ${{ matrix.cmake_args }}
78+
7979
make -j4
8080
mkdir -p ../../src/main/resources/native
81+
82+
# Platform-specific copy commands with verification
8183
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
82-
cp *.so ../../src/main/resources/native/${{ matrix.output_lib }}
84+
cp -v librandomx.so ../../src/main/resources/native/${{ matrix.output_lib }}
85+
ls -la ../../src/main/resources/native/
8386
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
84-
cp *.dylib ../../src/main/resources/native/${{ matrix.output_lib }}
87+
cp -v librandomx.dylib ../../src/main/resources/native/${{ matrix.output_lib }}
88+
ls -la ../../src/main/resources/native/
8589
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
86-
cp *.dll ../../src/main/resources/native/${{ matrix.output_lib }}
90+
cp -v librandomx.dll ../../src/main/resources/native/${{ matrix.output_lib }}
91+
ls -la ../../src/main/resources/native/
92+
fi
93+
shell: bash
94+
95+
- name: Verify library file
96+
run: |
97+
echo "Verifying library file in native resources directory"
98+
if [ -f "src/main/resources/native/${{ matrix.output_lib }}" ]; then
99+
echo "✅ Library file ${{ matrix.output_lib }} exists"
100+
else
101+
echo "❌ Library file ${{ matrix.output_lib }} is missing"
102+
exit 1
87103
fi
88104
shell: bash
89105

@@ -100,12 +116,29 @@ jobs:
100116
- name: Checkout code
101117
uses: actions/checkout@v4
102118

103-
- name: Download Dynamic Link Library Artifacts
119+
- name: Download all artifacts
104120
uses: actions/download-artifact@v4
105121
with:
106122
path: src/main/resources/native/
107-
pattern: librandomx-*
108-
- run: ls src/main/resources/native/
123+
merge-multiple: true
124+
125+
- name: Check for Apple Silicon Library
126+
run: |
127+
echo "Checking for macOS ARM64 library (should be precompiled locally)"
128+
if [ -f "src/main/resources/native/librandomx_macos_aarch64.dylib" ]; then
129+
echo "✅ Found precompiled Apple Silicon library"
130+
else
131+
echo "⚠️ WARNING: Apple Silicon library (librandomx_macos_aarch64.dylib) not found!"
132+
echo "⚠️ Please compile this library locally on an Apple Silicon Mac and commit it to the repository."
133+
echo "⚠️ Build will continue but the final JAR will not support Apple Silicon Macs."
134+
fi
135+
shell: bash
136+
137+
- name: List downloaded artifacts
138+
run: |
139+
echo "Contents of native resources directory:"
140+
ls -la src/main/resources/native/
141+
shell: bash
109142

110143
- name: Set up JDK
111144
uses: actions/setup-java@v4
@@ -126,6 +159,8 @@ jobs:
126159
release:
127160
runs-on: ubuntu-latest
128161
needs: build-java
162+
# Only run release job on master branch
163+
if: github.ref == 'refs/heads/master'
129164
steps:
130165
- name: Checkout code
131166
uses: actions/checkout@v4
@@ -149,34 +184,52 @@ jobs:
149184
- name: Find Main JAR File
150185
id: find_jar
151186
run: |
152-
JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" | head -n 1)
187+
JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar" | head -n 1)
153188
if [ -z "$JAR_FILE" ]; then
154189
echo "Error: No main JAR file found!"
155190
exit 1
156191
fi
157192
echo "Found JAR file: $JAR_FILE"
158193
echo "jar_file=$JAR_FILE" >> $GITHUB_ENV
194+
# Also set the JAR filename without path for easier use
195+
JAR_BASENAME=$(basename "$JAR_FILE")
196+
echo "jar_basename=$JAR_BASENAME" >> $GITHUB_ENV
159197
160198
- name: Generate Release Notes
199+
if: github.ref == 'refs/heads/master' # Only on master branch
161200
run: |
162-
echo "### Changelog" > RELEASE_NOTES.md
201+
echo "# xdagj-native-randomx v${{ env.VERSION }}" > RELEASE_NOTES.md
163202
echo "" >> RELEASE_NOTES.md
164-
echo "$(git log --pretty=format:"* %s (%h)" --no-merges $(git rev-list --tags --max-count=1)..HEAD)" >> RELEASE_NOTES.md
203+
echo "## Changes" >> RELEASE_NOTES.md
204+
echo "- Updated RandomX native libraries" >> RELEASE_NOTES.md
205+
echo "- Improved build process" >> RELEASE_NOTES.md
165206
echo "" >> RELEASE_NOTES.md
166-
echo "### Additional Notes" >> RELEASE_NOTES.md
167-
echo "- Build improvements." >> RELEASE_NOTES.md
207+
echo "## Native libraries included" >> RELEASE_NOTES.md
208+
echo "- Linux: x86_64" >> RELEASE_NOTES.md
209+
echo "- Windows: x86_64" >> RELEASE_NOTES.md
210+
echo "- macOS: x86_64, aarch64 (Apple Silicon)" >> RELEASE_NOTES.md
211+
echo "" >> RELEASE_NOTES.md
212+
echo "## System requirements" >> RELEASE_NOTES.md
213+
echo "- JDK 17 or later" >> RELEASE_NOTES.md
214+
echo "" >> RELEASE_NOTES.md
215+
echo "## Known issues" >> RELEASE_NOTES.md
168216
echo "- Known issues: None." >> RELEASE_NOTES.md
169217
170218
- name: Create Release using gh CLI
219+
if: github.ref == 'refs/heads/master' # Only on master branch
171220
run: |
172221
gh release create "v${{ env.VERSION }}" --title "xdagj-native-randomx v${{ env.VERSION }}" --notes-file RELEASE_NOTES.md
173222
env:
174223
GH_TOKEN: ${{ github.token }} # Use the token automatically generated by GitHub
175224

176225
- name: Rename output file
177-
run: mv "target/xdagj-native-randomx-${{ env.VERSION }}.jar" "target/xdagj-native-randomx.jar"
226+
run: |
227+
echo "Original JAR path: ${{ env.jar_file }}"
228+
cp "${{ env.jar_file }}" "target/xdagj-native-randomx.jar"
229+
echo "✅ Renamed JAR file created at target/xdagj-native-randomx.jar"
178230
179231
- name: Upload JAR using gh CLI
232+
if: github.ref == 'refs/heads/master' # Only on master branch
180233
run: |
181234
gh release upload "v${{ env.VERSION }}" target/xdagj-native-randomx.jar --clobber
182235
env:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@
2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
2424
/target/
25+
26+
.DS_Store

README.md

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Support the project with XDAG donations:
4040

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

4446
### **2. Build Steps**
4547

@@ -73,12 +75,19 @@ make -j4
7375
cp -i librandomx.dylib ../../src/main/resources/native/librandomx_macos_x86_64.dylib
7476
```
7577

76-
##### **macOS aarch64**
78+
##### **macOS aarch64 (Apple Silicon)**
79+
For Apple Silicon Macs (M1, M2, M3), use the provided script:
80+
```bash
81+
# Run from the project root
82+
./scripts/build-macos-arm64.sh
83+
```
84+
85+
Or manually:
7786
```bash
7887
cd randomx
7988
mkdir build && cd build
8089
cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON
81-
make -j4
90+
make -j$(sysctl -n hw.ncpu)
8291
cp -i librandomx.dylib ../../src/main/resources/native/librandomx_macos_aarch64.dylib
8392
```
8493

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

94104
#### **2.3 Compile Java Library**
95105
```bash
@@ -105,7 +115,7 @@ To include `xdagj-native-randomx` in your project, add the following dependency
105115
<dependency>
106116
<groupId>io.xdag</groupId>
107117
<artifactId>xdagj-native-randomx</artifactId>
108-
<version>0.2.0</version>
118+
<version>0.2.2</version>
109119
</dependency>
110120
```
111121

@@ -128,27 +138,27 @@ public class Example {
128138
byte[] keyBytes = key.getBytes(StandardCharsets.UTF_8);
129139

130140
// Get supported RandomX flags for the current CPU
131-
Set<RandomXFlag> flags = RandomXUtils.getFlagsSet();
141+
Set<RandomXFlag> flags = RandomXUtils.getRecommendedFlags();
132142
System.out.println("Supported flags: " + flags);
133-
int combinedFlags = RandomXFlag.toValue(flags);
134-
System.out.println("Combined flags value: " + combinedFlags);
135143

136-
// Initialize RandomX cache with the supported flags
144+
// Initialize RandomX cache (key will be set via template)
137145
RandomXCache cache = new RandomXCache(flags);
138-
cache.init(keyBytes);
139146

140147
// Create and configure RandomXTemplate using builder pattern
141148
byte[] hash;
142149
try (RandomXTemplate template = RandomXTemplate.builder()
143150
.cache(cache)
144-
.miningMode(false) // Set to false for normal hashing mode
151+
.miningMode(false)
145152
.flags(flags)
146153
.build()) {
147154

148-
// Initialize the template with the configured settings
155+
// Set the key for RandomX operations. This will initialize the cache.
156+
template.changeKey(keyBytes);
157+
158+
// Initialize the template's VM with the configured settings
149159
template.init();
150160

151-
// Calculate hash of the input key
161+
// Calculate hash of the input
152162
hash = template.calculateHash(keyBytes);
153163
}
154164

@@ -174,10 +184,10 @@ public class Example {
174184
### Linux Performance Results
175185
| Benchmark | Mode | Cnt | Score | Error | Units |
176186
|:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:|
177-
| RandomXBenchmark.lightBatch | thrpt | | 328.736 | | ops/s |
178-
| RandomXBenchmark.lightNoBatch | thrpt | | 325.383 | | ops/s |
179-
| RandomXBenchmark.miningBatch | thrpt | | 2777.939 | | ops/s |
180-
| RandomXBenchmark.miningNoBatch | thrpt | | 2817.811 | | ops/s |
187+
| RandomXBenchmark.lightBatch | thrpt | | 416.114 | | ops/s |
188+
| RandomXBenchmark.lightNoBatch | thrpt | | 424.865 | | ops/s |
189+
| RandomXBenchmark.miningBatch | thrpt | | 1818.991 | | ops/s |
190+
| RandomXBenchmark.miningNoBatch | thrpt | | 2191.774 | | ops/s |
181191

182192
---
183193

@@ -186,24 +196,34 @@ public class Example {
186196
- **CPU**: Apple M3 Pro
187197
- **RAM**: 36 GB
188198
- **thread**: 8
189-
- **RandomX Flags**: [DEFAULT, HARD_AES, SECURE]
190-
191-
JIT flag will cause jvm to crash in MacOS
199+
- **RandomX Flags**: [DEFAULT, JIT, SECURE]
192200

193201
### MacOS Performance Results
194-
| Benchmark | Mode | Cnt | Score | Error | Units |
195-
|:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:|
196-
| RandomXBenchmark.lightBatch | thrpt | | 32.864 | | ops/s |
197-
| RandomXBenchmark.lightNoBatch | thrpt | | 33.683 | | ops/s |
198-
| RandomXBenchmark.miningBatch | thrpt | | 554.966 | | ops/s |
199-
| RandomXBenchmark.miningNoBatch | thrpt | | 570.060 | | ops/s |
202+
| Benchmark | Mode | Cnt | Score | Error | Units |
203+
|:------------------------------:|:-----:|:---:|:--------:|:------:|:-----:|
204+
| RandomXBenchmark.lightBatch | thrpt | | 416.114 | | ops/s |
205+
| RandomXBenchmark.lightNoBatch | thrpt | | 424.865 | | ops/s |
206+
| RandomXBenchmark.miningBatch | thrpt | | 1818.991 | | ops/s |
207+
| RandomXBenchmark.miningNoBatch | thrpt | | 2191.774 | | ops/s |
200208

201209
---
202210

203211
## Contribution
204212

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

215+
### **Contributing to the library**
216+
217+
If you're submitting changes that might affect the native libraries:
218+
219+
1. For platform-specific changes, compile the native library for your platform:
220+
* Linux x86_64, macOS x86_64, or Windows x86_64: Follow the compilation steps above.
221+
* macOS aarch64 (Apple Silicon): Must be compiled on an Apple Silicon Mac using provided script.
222+
223+
2. Commit both your code changes and the updated native library files.
224+
225+
3. GitHub Actions will build for other platforms and generate a complete multi-platform JAR.
226+
207227
For discussions or questions, contact the [xdagj community](https://github.com/XDagger/xdagj).
208228

209229
---

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.xdag</groupId>
88
<artifactId>xdagj-native-randomx</artifactId>
9-
<version>0.2.1</version>
9+
<version>0.2.2</version>
1010

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

2323
<!-- Dependency versions -->
2424
<commons-lang3.version>3.17.0</commons-lang3.version>
25-
<jna.version>5.15.0</jna.version>
26-
<lombok.version>1.18.34</lombok.version>
27-
<slf4j.version>2.0.16</slf4j.version>
28-
<junit.version>5.10.3</junit.version>
25+
<jna.version>5.17.0</jna.version>
26+
<lombok.version>1.18.38</lombok.version>
27+
<slf4j.version>2.0.17</slf4j.version>
28+
<junit.version>5.12.2</junit.version>
2929
<jmh.version>1.37</jmh.version>
3030

3131
<!-- Plugin versions -->

randomx

scripts/build-macos-arm64.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Script to build RandomX for Apple Silicon (M series chips)
4+
# This script should be run on an Apple Silicon Mac
5+
6+
# Check if running on ARM Mac
7+
if [[ $(uname -m) != "arm64" ]]; then
8+
echo "❌ This script must be run on an Apple Silicon Mac (M1/M2/M3)"
9+
exit 1
10+
fi
11+
12+
echo "🔍 Building RandomX library for Apple Silicon (ARM64)..."
13+
14+
# Navigate to randomx directory
15+
cd "$(dirname "$0")/../randomx" || exit 1
16+
17+
# Create build directory if it doesn't exist
18+
mkdir -p build
19+
cd build || exit 1
20+
21+
echo "🔧 Running CMake..."
22+
cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON
23+
24+
echo "🔨 Compiling RandomX..."
25+
make -j$(sysctl -n hw.ncpu)
26+
27+
# Create native resources directory if it doesn't exist
28+
mkdir -p ../../src/main/resources/native
29+
30+
echo "📦 Copying library to resources directory..."
31+
cp -vf librandomx.dylib ../../src/main/resources/native/librandomx_macos_aarch64.dylib
32+
33+
echo "✅ Build complete!"
34+
echo "Library location: src/main/resources/native/librandomx_macos_aarch64.dylib"
35+
echo ""
36+
echo "Please commit this file to your repository before pushing to GitHub."
37+
echo "This will allow GitHub Actions to package it with the other platform libraries."

0 commit comments

Comments
 (0)