Skip to content

Commit 0cf289a

Browse files
authored
Merge pull request #20 from Rushin2211/develop
Fixed the build and run error issues in Windows and Linux environments
2 parents 333c288 + 29ef450 commit 0cf289a

File tree

11 files changed

+86
-74
lines changed

11 files changed

+86
-74
lines changed

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

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ on:
44
push:
55
branches:
66
- master
7+
- develop
78
pull_request:
89
branches:
910
- master
11+
- develop
1012
jobs:
1113
build-randomx:
1214
runs-on: ${{ matrix.os }}
@@ -18,25 +20,25 @@ jobs:
1820
# Linux - x86_64
1921
- os: ubuntu-latest
2022
arch: x86_64
21-
cmake_args: '-DARCH=x86_64 -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"'
23+
cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"'
2224
artifact_name: 'librandomx_linux_x86_64.so'
2325
output_lib: 'librandomx_linux_x86_64.so'
2426
# macOS - x86_64
2527
- os: macos-latest
2628
arch: x86_64
27-
cmake_args: '-DARCH=x86_64 -DBUILD_SHARED_LIBS=ON'
29+
cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON'
2830
artifact_name: 'librandomx_macos_x86_64.dylib'
2931
output_lib: 'librandomx_macos_x86_64.dylib'
3032
# macOS - aarch64
3133
- os: macos-latest
3234
arch: aarch64
33-
cmake_args: '-DARCH=arm64 -DBUILD_SHARED_LIBS=ON'
35+
cmake_args: '-DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON'
3436
artifact_name: 'librandomx_macos_aarch64.dylib'
3537
output_lib: 'librandomx_macos_aarch64.dylib'
3638
# Windows - x86_64
3739
- os: windows-latest
3840
arch: x86_64
39-
cmake_args: '-G "MinGW Makefiles" -DARCH=native -DBUILD_SHARED_LIBS=ON'
41+
cmake_args: '-G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON'
4042
artifact_name: 'librandomx_windows_x86_64.dll'
4143
output_lib: 'librandomx_windows_x86_64.dll'
4244
exclude:
@@ -74,7 +76,7 @@ jobs:
7476
cd randomx
7577
mkdir build && cd build
7678
cmake .. ${{ matrix.cmake_args }}
77-
make
79+
make -j4
7880
mkdir -p ../../src/main/resources/native
7981
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
8082
cp *.so ../../src/main/resources/native/${{ matrix.output_lib }}
@@ -125,57 +127,57 @@ jobs:
125127
runs-on: ubuntu-latest
126128
needs: build-java
127129
steps:
128-
- name: Checkout code
129-
uses: actions/checkout@v4
130-
131-
- name: Install gh CLI
132-
run: sudo apt-get install -y gh
133-
134-
- name: Extract Version from pom.xml
135-
id: extract_version
136-
run: |
137-
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
138-
echo "VERSION=$VERSION" >> $GITHUB_ENV
139-
echo "Extracted version: $VERSION"
140-
141-
- name: Download JAR Artifact
142-
uses: actions/download-artifact@v4
143-
with:
144-
name: xdagj-native-randomx-jar
145-
path: target/
146-
147-
- name: Find Main JAR File
148-
id: find_jar
149-
run: |
150-
JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" | head -n 1)
151-
if [ -z "$JAR_FILE" ]; then
152-
echo "Error: No main JAR file found!"
153-
exit 1
154-
fi
155-
echo "Found JAR file: $JAR_FILE"
156-
echo "jar_file=$JAR_FILE" >> $GITHUB_ENV
157-
158-
- name: Generate Release Notes
159-
run: |
160-
echo "### Changelog" > RELEASE_NOTES.md
161-
echo "" >> RELEASE_NOTES.md
162-
echo "$(git log --pretty=format:"* %s (%h)" --no-merges $(git rev-list --tags --max-count=1)..HEAD)" >> RELEASE_NOTES.md
163-
echo "" >> RELEASE_NOTES.md
164-
echo "### Additional Notes" >> RELEASE_NOTES.md
165-
echo "- Build improvements." >> RELEASE_NOTES.md
166-
echo "- Known issues: None." >> RELEASE_NOTES.md
167-
168-
- name: Create Release using gh CLI
169-
run: |
170-
gh release create "v${{ env.VERSION }}" --title "xdagj-native-randomx v${{ env.VERSION }}" --notes-file RELEASE_NOTES.md
171-
env:
172-
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
173-
174-
- name: Rename output file
175-
run: mv "target/xdagj-native-randomx-${{ env.VERSION }}.jar" "target/xdagj-native-randomx.jar"
176-
177-
- name: Upload JAR using gh CLI
178-
run: |
179-
gh release upload "v${{ env.VERSION }}" target/xdagj-native-randomx.jar --clobber
180-
env:
181-
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
130+
- name: Checkout code
131+
uses: actions/checkout@v4
132+
133+
- name: Install gh CLI
134+
run: sudo apt-get install -y gh
135+
136+
- name: Extract Version from pom.xml
137+
id: extract_version
138+
run: |
139+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
140+
echo "VERSION=$VERSION" >> $GITHUB_ENV
141+
echo "Extracted version: $VERSION"
142+
143+
- name: Download JAR Artifact
144+
uses: actions/download-artifact@v4
145+
with:
146+
name: xdagj-native-randomx-jar
147+
path: target/
148+
149+
- name: Find Main JAR File
150+
id: find_jar
151+
run: |
152+
JAR_FILE=$(find target/ -type f -name "xdagj-native-randomx-*.jar" | head -n 1)
153+
if [ -z "$JAR_FILE" ]; then
154+
echo "Error: No main JAR file found!"
155+
exit 1
156+
fi
157+
echo "Found JAR file: $JAR_FILE"
158+
echo "jar_file=$JAR_FILE" >> $GITHUB_ENV
159+
160+
- name: Generate Release Notes
161+
run: |
162+
echo "### Changelog" > RELEASE_NOTES.md
163+
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
165+
echo "" >> RELEASE_NOTES.md
166+
echo "### Additional Notes" >> RELEASE_NOTES.md
167+
echo "- Build improvements." >> RELEASE_NOTES.md
168+
echo "- Known issues: None." >> RELEASE_NOTES.md
169+
170+
- name: Create Release using gh CLI
171+
run: |
172+
gh release create "v${{ env.VERSION }}" --title "xdagj-native-randomx v${{ env.VERSION }}" --notes-file RELEASE_NOTES.md
173+
env:
174+
GH_TOKEN: ${{ github.token }} # Use the token automatically generated by GitHub
175+
176+
- name: Rename output file
177+
run: mv "target/xdagj-native-randomx-${{ env.VERSION }}.jar" "target/xdagj-native-randomx.jar"
178+
179+
- name: Upload JAR using gh CLI
180+
run: |
181+
gh release upload "v${{ env.VERSION }}" target/xdagj-native-randomx.jar --clobber
182+
env:
183+
GH_TOKEN: ${{ github.token }} # Use the token automatically generated by GitHub

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Compile and copy the appropriate shared library for your platform:
5959
```bash
6060
cd randomx
6161
mkdir build && cd build
62-
cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON
62+
cmake .. -DCMAKE_BUILD_TYPE=Release -DARCH=native -DBUILD_SHARED_LIBS=ON -DCMAKE_C_FLAGS="-fPIC"
6363
make -j4
6464
cp -i librandomx.so ../../src/main/resources/native/librandomx_linux_x86_64.so
6565
```
@@ -175,9 +175,9 @@ public class Example {
175175
| Benchmark | Mode | Cnt | Score | Error | Units |
176176
|:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:|
177177
| RandomXBenchmark.lightBatch | thrpt | | 328.736 | | ops/s |
178-
| RandomXBenchmark.lightNoBatch | thrpt | | 325.383 | | s/op |
179-
| RandomXBenchmark.miningBatch | thrpt | | 2777.939 | | s/op |
180-
| RandomXBenchmark.miningNoBatch | thrpt | | 2817.811 | | s/op |
178+
| RandomXBenchmark.lightNoBatch | thrpt | | 325.383 | | ops/s |
179+
| RandomXBenchmark.miningBatch | thrpt | | 2777.939 | | ops/s |
180+
| RandomXBenchmark.miningNoBatch | thrpt | | 2817.811 | | ops/s |
181181

182182
---
183183

@@ -194,9 +194,9 @@ JIT flag will cause jvm to crash in MacOS
194194
| Benchmark | Mode | Cnt | Score | Error | Units |
195195
|:------------------------------:|:-----:|:---:|:-------:|:------:|:-----:|
196196
| RandomXBenchmark.lightBatch | thrpt | | 32.864 | | ops/s |
197-
| RandomXBenchmark.lightNoBatch | thrpt | | 33.683 | | s/op |
198-
| RandomXBenchmark.miningBatch | thrpt | | 554.966 | | s/op |
199-
| RandomXBenchmark.miningNoBatch | thrpt | | 570.060 | | s/op |
197+
| RandomXBenchmark.lightNoBatch | thrpt | | 33.683 | | ops/s |
198+
| RandomXBenchmark.miningBatch | thrpt | | 554.966 | | ops/s |
199+
| RandomXBenchmark.miningNoBatch | thrpt | | 570.060 | | ops/s |
200200

201201
---
202202

@@ -206,4 +206,4 @@ We welcome contributions to improve the project! Please feel free to submit issu
206206

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

209-
---
209+
---

src/main/java/io/xdag/crypto/randomx/RandomXJNALoader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ public static RandomXJNA getInstance() {
7777
synchronized (LOCK) {
7878
result = instance;
7979
if (result == null) {
80-
instance = result = Native.load("randomx", RandomXJNA.class);
80+
String osName = System.getProperty("os.name").toLowerCase();
81+
if (osName.contains("win")) {
82+
String libFilePath = "native/librandomx_windows_x86_64.dll";
83+
instance = result = Native.load(libFilePath, RandomXJNA.class);
84+
} else {
85+
instance = result = Native.load("randomx", RandomXJNA.class);
86+
}
8187
}
8288
}
8389
}
@@ -119,7 +125,9 @@ public static void loadLibrary(String libraryName) {
119125
*/
120126
private static String getLibraryFileName(String libraryName, String os, String arch) {
121127
if (os.contains("win")) {
122-
return String.format("native/%s_windows_%s.dll", libraryName, arch);
128+
if (StringUtils.containsAny(arch, "amd64", "x86_64")) {
129+
return String.format("native/%s_windows_x86_64.dll", libraryName);
130+
}
123131
} else if (os.contains("mac")) {
124132
return String.format("native/%s_macos_%s.dylib", libraryName, arch);
125133
} else if (StringUtils.contains(os, "linux")) {
-4 KB
Binary file not shown.

src/test/java/io/xdag/crypto/randomx/RandomXBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ public static void main(String[] args) throws Exception {
181181

182182
new Runner(opt).run();
183183
}
184-
}
184+
}

src/test/java/io/xdag/crypto/randomx/RandomXCacheTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ public void testInit() {
6262
} // Cache is automatically released here.
6363
}
6464

65-
}
65+
}

src/test/java/io/xdag/crypto/randomx/RandomXDatasetTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ void testInitialization() {
7272
}
7373
}
7474

75-
}
75+
}

src/test/java/io/xdag/crypto/randomx/RandomXJNALoaderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ public class RandomXJNALoaderTest {
4040
public void testLibraryLoading() {
4141
assertNotNull(RandomXJNALoader.getInstance(), "RandomXJNA instance should not be null.");
4242
}
43+
4344
}

src/test/java/io/xdag/crypto/randomx/RandomXTemplateTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ public void testChangeKey() {
117117
assertEquals("3910d7b054df9ba920e2f7e103aa2c1fc4597b13d1793f1ab08c1c9c922709c0", hex.formatHex(hash));
118118
}
119119

120-
}
120+
}

src/test/java/io/xdag/crypto/randomx/RandomXTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ void testBatchHash() {
140140
assertEquals("c36d4ed4191e617309867ed66a443be4075014e2b061bcdaf9ce7b721d2b77a8", hex.formatHex(hash3));
141141
}
142142

143-
}
143+
}

0 commit comments

Comments
 (0)