Skip to content

Commit 4e94079

Browse files
committed
CI(github): add math check and cross-platform build
1 parent e5428a8 commit 4e94079

7 files changed

Lines changed: 221 additions & 50 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7+
8+
name: arm64-Platform Matrix
9+
10+
on:
11+
push:
12+
branches: [ "exp/arm64" ]
13+
pull_request:
14+
branches: [ "exp/arm64" ]
15+
16+
jobs:
17+
build:
18+
19+
name: ${{ matrix.os }} - ${{ matrix.os-version }}
20+
runs-on: ${{ matrix.runner }}
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
# Apple Silicon runners (using latest available)
27+
- os: macOS
28+
arch: arm64
29+
runner: macos-13
30+
os-version: "13"
31+
- os: macOS
32+
arch: arm64
33+
runner: macos-14
34+
os-version: "14"
35+
- os: macOS
36+
arch: arm64
37+
runner: macos-15
38+
os-version: "15"
39+
40+
permissions:
41+
contents: read
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
- name: Set up JDK 17
46+
uses: actions/setup-java@v4
47+
with:
48+
java-version: '17'
49+
distribution: 'temurin'
50+
51+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
52+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
53+
- name: Setup Gradle
54+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
55+
56+
- name: Build with Gradle Wrapper
57+
run: ./gradlew clean build --no-daemon

.github/workflows/math-check.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Check Math Usage
2+
3+
on:
4+
push:
5+
branches: [ "exp/arm64" ]
6+
pull_request:
7+
branches: [ "exp/arm64" ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
check-math:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Check for java.lang.Math usage
18+
id: check-math
19+
run: |
20+
echo "Checking for java.lang.Math usage..."
21+
22+
find . -type f -name "*.java" -exec cat {} \; > all_java_content.txt
23+
24+
echo "Files with Math usage:" > math_usage.txt
25+
26+
find . -type f -name "*.java" | while read file; do
27+
if grep -l "^import[[:space:]]*java\.lang\.Math\b" "$file" > /dev/null; then
28+
echo "$file (contains import)" >> math_usage.txt
29+
continue
30+
fi
31+
32+
if perl -0777 -ne 'print "$ARGV\n" if /java\s*\.\s*lang\s*\.\s*Math\s*\./' "$file" > /dev/null; then
33+
echo "$file (contains fully qualified)" >> math_usage.txt
34+
continue
35+
fi
36+
37+
if perl -0777 -ne '
38+
s!/\*.*?\*/!!gs;
39+
s!//[^\n]*!!g;
40+
print "$ARGV\n" if /(?<!Strict)(?<![\w\.])Math\s*\./' "$file" > /dev/null; then
41+
echo "$file (contains Math usage)" >> math_usage.txt
42+
fi
43+
done
44+
45+
if [ -s math_usage.txt ]; then
46+
echo "Found Math usage in the following files:"
47+
cat math_usage.txt
48+
echo "math_found=true" >> $GITHUB_OUTPUT
49+
else
50+
echo "No Math usage found"
51+
echo "math_found=false" >> $GITHUB_OUTPUT
52+
fi
53+
54+
rm -f all_java_content.txt
55+
56+
- name: Upload findings
57+
if: steps.check-math.outputs.math_found == 'true'
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: math-usage-report
61+
path: math_usage.txt
62+
63+
- name: Create comment
64+
if: github.event_name == 'pull_request' && steps.check-math.outputs.math_found == 'true'
65+
uses: actions/github-script@v6
66+
with:
67+
script: |
68+
const fs = require('fs');
69+
const findings = fs.readFileSync('math_usage.txt', 'utf8');
70+
const body = `### Math Usage Detection Results
71+
72+
Found usage of \`java.lang.Math\` in the following files:
73+
74+
\`\`\`
75+
${findings}
76+
\`\`\`
77+
78+
Please review if this usage is intended.`;
79+
80+
await github.rest.issues.createComment({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
issue_number: context.issue.number,
84+
body: body
85+
});
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7+
8+
name: X86_64-Platform Matrix
9+
10+
on:
11+
push:
12+
branches: [ "exp/arm64" ]
13+
pull_request:
14+
branches: [ "exp/arm64" ]
15+
16+
jobs:
17+
build:
18+
19+
name: ${{ matrix.os }} - ${{ matrix.os-version }}
20+
runs-on: ${{ matrix.runner }}
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
# Macos Intel runners
27+
- os: macOS
28+
arch: x86_64
29+
runner: macos-12
30+
os-version: "12"
31+
- os: macOS
32+
arch: x86_64
33+
runner: macos-13
34+
os-version: "13"
35+
- os: macOS
36+
arch: x86_64
37+
runner: macos-14
38+
os-version: "14"
39+
- os: macOS
40+
arch: x86_64
41+
runner: macos-15
42+
os-version: "15"
43+
# Linux x86_64 runners
44+
- os: Linux
45+
arch: x86_64
46+
runner: ubuntu-20.04
47+
os-version: "20.04"
48+
- os: Linux
49+
arch: x86_64
50+
runner: ubuntu-22.04
51+
os-version: "22.04"
52+
53+
permissions:
54+
contents: read
55+
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: Set up JDK 8
59+
uses: actions/setup-java@v4
60+
with:
61+
java-version: '8'
62+
distribution: 'zulu'
63+
64+
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
65+
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
66+
- name: Setup Gradle
67+
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
68+
69+
- name: Build with Gradle Wrapper
70+
run: ./gradlew clean build --no-daemon

build.gradle

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
import org.gradle.nativeplatform.platform.internal.Architectures
21
allprojects {
32
version = "1.0.0"
43
apply plugin: "java-library"
54
}
65

7-
static def isX86() {
8-
def arch = System.getProperty("os.arch").toLowerCase()
9-
return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch)
10-
}
11-
12-
static def isArm64() {
13-
def arch = System.getProperty("os.arch").toLowerCase()
14-
return new Architectures.KnownArchitecture("arm64", "aarch64").isAlias(arch)
15-
}
16-
17-
if (isArm64() && !JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
18-
throw new GradleException("Java 17 or later is required to build Java-Tron for arm64.\n" +
19-
" Detected version ${JavaVersion.current()}")
20-
}
21-
22-
if (isX86() && !JavaVersion.current().isJava8()) {
23-
throw new GradleException("Java 8 is required to build Java-Tron for x86.\n" +
24-
" Detected version ${JavaVersion.current()}")
25-
}
26-
276
subprojects {
287
apply plugin: "jacoco"
298
apply plugin: "maven-publish"

chainbase/src/main/java/org/tron/common/utils/Commons.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public static void adjustBalance(AccountStore accountStore, AccountCapsule accou
7777
String.format("%s insufficient balance, balance: %d, amount: %d",
7878
StringUtil.createReadableString(account.createDbKey()), balance, -amount));
7979
}
80-
account.setBalance(Math.addExact(balance, amount));
80+
account.setBalance(Math
81+
.addExact(balance, amount));
8182
accountStore.put(account.getAddress().toByteArray(), account);
8283
}
8384

common/src/main/java/org/tron/core/config/args/Storage.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,7 @@ public class Storage {
175175
private final Map<String, Sha256Hash> dbRoots = Maps.newConcurrentMap();
176176

177177
public static String getDbEngineFromConfig(final Config config) {
178-
if (Arch.isArm64() && !System.getenv().containsKey("CI")) {
179-
logger.info("Arm64 architecture detected, using RocksDB as db engine, ignore config.");
180-
return ROCKS_DB_ENGINE;
181-
}
182-
return config.hasPath(DB_ENGINE_CONFIG_KEY)
183-
? config.getString(DB_ENGINE_CONFIG_KEY) : DEFAULT_DB_ENGINE;
178+
return ROCKS_DB_ENGINE;
184179
}
185180

186181
public static Boolean getDbVersionSyncFromConfig(final Config config) {

platform/build.gradle

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
1-
import org.gradle.nativeplatform.platform.internal.Architectures
21

32
description = "platform – a distributed consensus arithmetic for blockchain."
43

5-
6-
static def isX86() {
7-
def arch = System.getProperty("os.arch").toLowerCase()
8-
return Architectures.X86_64.isAlias(arch) || Architectures.X86.isAlias(arch)
9-
}
10-
11-
if (isX86()) {
12-
ext {
13-
leveldbGroup = "org.fusesource.leveldbjni"
14-
leveldbName = "leveldbjni-all"
15-
leveldbVersion = "1.8"
16-
rocksDBVersion = "5.15.10"
17-
}
18-
} else {
19-
ext {
20-
leveldbGroup = "com.halibobor"
21-
leveldbName = "leveldbjni-all"
22-
leveldbVersion = "1.18.3"
23-
rocksDBVersion = "7.7.3"
24-
}
4+
ext {
5+
leveldbGroup = "com.halibobor"
6+
leveldbName = "leveldbjni-all"
7+
leveldbVersion = "1.18.3"
8+
rocksDBVersion = "7.7.3"
259
}
2610

2711
sourceSets {
@@ -43,5 +27,5 @@ dependencies {
4327
}
4428

4529
tasks.withType(JavaCompile).configureEach {
46-
source = isX86() ? sourceSets.x86.java : sourceSets.arm.java
30+
source = sourceSets.arm.java
4731
}

0 commit comments

Comments
 (0)