浏览代码

Configure GitHub Actions for native

Him188 3 年之前
父节点
当前提交
d01dc577a2

+ 0 - 61
.github/actions/upload-build-artifacts/action.yml

@@ -1,61 +0,0 @@
-name: Upload mirai build artifacts
-author: Karlatemp
-description: Not exists
-
-runs:
-  using: composite
-  steps:
-    - name: Ensure build
-      shell: bash
-      run: >
-        ./gradlew build publishToMavenLocal --scan
-        --exclude-task allTests
-        --exclude-task jvmTest
-        --exclude-task androidTest
-        --exclude-task test
-        --exclude-task check
-
-    - name: Upload mirai-core-utils
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-core-utils
-        path: mirai-core-utils/build/libs
-
-    - name: Upload mirai-core-api
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-core-api
-        path: mirai-core-api/build/libs
-
-    - name: Upload mirai-core
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-core
-        path: mirai-core/build/libs
-
-    - name: Upload mirai-core-all
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-core-all
-        path: mirai-core-all/build/libs
-
-
-    - name: Upload mirai-console
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-console
-        path: mirai-console/backend/mirai-console/build/libs
-
-    - name: Upload mirai-console-terminal
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-console-terminal
-        path: mirai-console/frontend/mirai-console-terminal/build/libs
-
-
-    - name: Upload mirai-console-gradle
-      uses: actions/upload-artifact@v3
-      with:
-        name: mirai-console-gradle
-        path: mirai-console/tools/gradle-plugin/build/libs
-

+ 88 - 0
.github/codegen/generate-build-native.ws.kts

@@ -0,0 +1,88 @@
+/*
+ * Copyright 2019-2022 Mamoe Technologies and contributors.
+ *
+ * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ * https://github.com/mamoe/mirai/blob/dev/LICENSE
+ */
+
+val env = "\${{ env.gradleArgs }}"
+
+val isUbunutu = "\${{ env.isUbuntu == 'true' }}"
+val isWindows = "\${{ env.isWindows == 'true' }}"
+val isMac = "\${{ env.isMac == 'true' }}"
+
+
+val template = """
+      - if: CONDITION
+        name: "Compile mirai-core-api for macosArm64"
+        run: ./gradlew :mirai-core-api:compileKotlinMacosArm64 :mirai-core-api:compileTestKotlinMacosArm64 $env
+
+      - if: CONDITION
+        name: "Link mirai-core-api for macosArm64"
+        run: ./gradlew mirai-core-api:linkDebugTestMacosArm64 $env
+
+      - if: CONDITION
+        name: "Test mirai-core-api for macosArm64"
+        run: ./gradlew :mirai-core-api:macosArm64Test $env
+""".trimIndent()
+
+val output = buildString {
+    val title = "############# GENERATED FROM generate-build-native.ws.kts #############"
+    appendLine("#".repeat(title.length))
+    appendLine(title)
+    appendLine("#".repeat(title.length))
+    appendLine()
+
+
+
+    listOf("mirai-core-utils", "mirai-core-api", "mirai-core").forEach { moduleName ->
+        appendLine(
+            """
+           - name: "Commonize mirai-core-api"
+             run: ./gradlew :mirai-core-api:commonize $env
+        """.trimIndent().replace("mirai-core-api", moduleName)
+        )
+        appendLine()
+    }
+
+    listOf("mirai-core-utils", "mirai-core-api", "mirai-core").forEach { moduleName ->
+        appendLine("# $moduleName")
+        appendLine()
+        appendLine(
+            """
+           - name: "Compile mirai-core-api for common"
+             run: ./gradlew :mirai-core-api:compileCommonMainKotlinMetadata $env
+
+           - name: "Compile mirai-core-api for native"
+             run: ./gradlew :mirai-core-api:compileNativeMainKotlinMetadata $env
+
+           - name: "Compile mirai-core-api for unix-like"
+             run: ./gradlew :mirai-core-api:compileUnixMainKotlinMetadata $env
+        """.trimIndent().replace("mirai-core-api", moduleName)
+        )
+        appendLine()
+
+        listOf("macosX64" to isMac, "mingwX64" to isWindows, "linuxX64" to isUbunutu).forEach { (target, condition) ->
+            appendLine(useTemplate(moduleName, target, condition))
+            appendLine()
+            appendLine()
+        }
+        appendLine()
+    }
+
+    this.trimEnd().let { c -> clear().appendLine(c) } // remove trailing empty lines
+
+    appendLine()
+    appendLine("#".repeat(title.length))
+}
+println(output.prependIndent(" ".repeat(6)))
+
+fun useTemplate(moduleName: String, target: String, condition: String) = template
+    .replace("mirai-core-api", moduleName)
+    .replace("macosArm64", target)
+    .replace("MacosArm64", target.replaceFirstChar { it.uppercaseChar() })
+    .replace("CONDITION", condition)
+    // Link release artifacts to save memory
+    .replace("linkDebugTestMingwX64", "linkReleaseTestMingwX64")

+ 673 - 23
.github/workflows/build.yml

@@ -1,46 +1,696 @@
-name: Build
+name: Build mirai
 
 on: [ push, pull_request ]
 
 jobs:
-  build-mirai:
+  build-mirai-jvm:
+    name: "JVM modules (${{ matrix.os }})"
     runs-on: ${{ matrix.os }}
     strategy:
       fail-fast: false
       matrix:
-        os: # mirai build requires a minimum system memory of 8 GB, while Windows and Ubuntu VMs provides only 7 GB. See https://github.com/mamoe/mirai/actions/runs/1608172113 for details.
-#          - windows-latest
+        os:
+          - windows-2022
+          - macos-12
+    env:
+      gradleArgs: --scan "-Dkotlin.compiler.execution.strategy=in-process" --no-daemon
+      isMac: ${{ startsWith(matrix.os, 'macos') }}
+      isWindows: ${{ startsWith(matrix.os, 'windows') }}
+      isUbuntu: ${{ startsWith(matrix.os, 'ubuntu') }}
+      isUnix: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
+    steps:
+      - uses: actions/checkout@v2
+      - run: git submodule update --init --recursive
+
+      - uses: actions/setup-java@v2
+        with:
+          distribution: 'adopt'
+          java-version: '11'
+
+      - if: ${{ env.isUnix == 'true' }}
+        run: chmod -R 777 *
+
+
+      # Disable Gradle daemon and Kotlin compiler daemon to save memory — 7 GB for Windows and Ubuntu hosts.
+
+      - name: Clean and download dependencies
+        run: ./gradlew clean ${{ env.gradleArgs }}
+
+      # Build modules separately to save memory
+
+      - name: "Compile mirai-core-utils"
+        run: ./gradlew :mirai-core-utils:compileKotlinJvm :mirai-core-utils:compileKotlinAndroid ${{ env.gradleArgs }}
+
+      - name: "Test mirai-core-utils"
+        run: ./gradlew :mirai-core-utils:jvmTest :mirai-core-utils:androidTest ${{ env.gradleArgs }}
+
+      - name: "Check mirai-core-utils Android API Level"
+        run: ./gradlew :mirai-core-utils:checkAndroidApiLevel ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-core-api"
+        run: ./gradlew :mirai-core-api:compileKotlinJvm :mirai-core-api:compileKotlinAndroid ${{ env.gradleArgs }}
+
+      - name: "Test mirai-core-api"
+        run: ./gradlew :mirai-core-api:jvmTest :mirai-core-api:androidTest ${{ env.gradleArgs }}
+
+      - name: "Check mirai-core-api JVM ABI"
+        run: ./gradlew :mirai-core-api:apiCheckAll ${{ env.gradleArgs }}
+
+      - name: "Check mirai-core-api Android API Level"
+        run: ./gradlew :mirai-core-api:checkAndroidApiLevel ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-core"
+        run: ./gradlew :mirai-core:compileKotlinJvm :mirai-core:compileKotlinAndroid ${{ env.gradleArgs }}
+
+      - name: "Test mirai-core"
+        run: ./gradlew :mirai-core:jvmTest :mirai-core:androidTest ${{ env.gradleArgs }}
+
+      - name: "Check mirai-core Android API Level"
+        run: ./gradlew :mirai-core:checkAndroidApiLevel ${{ env.gradleArgs }}
+
+
+      - name: Upload mirai-core-utils
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-core-utils
+          path: mirai-core-utils/build/libs
+
+      - name: Upload mirai-core-api
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-core-api
+          path: mirai-core-api/build/libs
+
+      - name: Upload mirai-core
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-core
+          path: mirai-core/build/libs
+
+      - name: "Build mirai-core-all"
+        run: ./gradlew :mirai-core-all:shadowJar ${{ env.gradleArgs }}
+
+      - name: Upload mirai-core-all
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-core-all
+          path: mirai-core-all/build/libs
+
+
+      # Console and tools
+
+
+      - name: "Compile mirai-console"
+        run: ./gradlew :mirai-console:assemble ${{ env.gradleArgs }}
+
+      - name: "Test mirai-console"
+        run: ./gradlew :mirai-console:check ${{ env.gradleArgs }}
+
+      - name: "Check JVM ABI"
+        run: ./gradlew :mirai-console:apiCheckAll ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-console integration-test"
+        run: ./gradlew :mirai-console:check ${{ env.gradleArgs }}
+
+      - name: "Test mirai-console integration-test"
+        run: ./gradlew :mirai-console.integration-test:check ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-console-terminal"
+        run: ./gradlew :mirai-console-terminal:assemble ${{ env.gradleArgs }}
+
+      - name: "Test mirai-console-terminal"
+        run: ./gradlew :mirai-console-terminal:check ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-console-gradle"
+        run: ./gradlew :mirai-console-gradle:assemble ${{ env.gradleArgs }}
+
+      - name: "Test mirai-console-gradle"
+        run: ./gradlew :mirai-console-gradle:check ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-console-intellij"
+        run: ./gradlew :mirai-console-intellij:assemble ${{ env.gradleArgs }}
+
+      - name: "Build mirai-console-intellij plugin"
+        run: ./gradlew :mirai-console-intellij:buildPlugin ${{ env.gradleArgs }}
+
+      - name: "Test mirai-console-intellij"
+        run: ./gradlew :mirai-console-intellij:check ${{ env.gradleArgs }}
+
+
+      - name: "Compile mirai-logging"
+        run:
+          ./gradlew
+          :mirai-logging-log4j2:assemble
+          :mirai-logging-slf4j:assemble
+          :mirai-logging-slf4j-logback:assemble
+          :mirai-logging-slf4j-simple:assemble
+          ${{ env.gradleArgs }}
+
+      - name: "Test mirai-logging"
+        run:
+          ./gradlew
+          :mirai-logging-log4j2:check
+          :mirai-logging-slf4j:check
+          :mirai-logging-slf4j-logback:check
+          :mirai-logging-slf4j-simple:check
+          ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: Ensure KDoc valid
+        run: ./gradlew dokkaHtmlMultiModule
+
+      - name: Upload mirai-console
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-console
+          path: mirai-console/backend/mirai-console/build/libs
+
+      - name: Upload mirai-console-terminal
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-console-terminal
+          path: mirai-console/frontend/mirai-console-terminal/build/libs
+
+      - name: Upload mirai-console-compiler-annotations
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-console-compiler-annotations
+          path: mirai-console/tools/mirai-console-compiler-annotations/build/libs
+
+      - name: Upload mirai-console-compiler-common
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-console-compiler-common
+          path: mirai-console/tools/mirai-console-compiler-common/build/libs
+
+      - name: Upload mirai-console-intellij
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-console-intellij
+          path: mirai-console/tools/intelli-plugin/build/distribution
+
+      - name: Upload mirai-logging-log4j2
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-logging-log4j2
+          path: logging/mirai-logging-log4j2/build/libs
+
+      - name: Upload mirai-logging-slf4j
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-logging-slf4j
+          path: logging/mirai-logging-slf4j/build/libs
+
+      - name: Upload mirai-logging-slf4j-logback
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-logging-slf4j-logback
+          path: logging/mirai-logging-slf4j-logback/build/libs
+
+      - name: Upload mirai-logging-slf4j-simple
+        uses: actions/upload-artifact@v3
+        with:
+          name: mirai-logging-slf4j-simple
+          path: logging/mirai-logging-slf4j-simple/build/libs
+
+
+
+
+
+  build-mirai-core-native:
+    name: "core-native (${{ matrix.os }})"
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os:
+          - windows-2022
+          #          - windows-2019 # Our config works only for Windows 2022 servers (Using some absolute paths)
+          - macos-12
           - macos-11
-#          - ubuntu-latest
+    env:
+      # Disabling Gradle daemon and Kotlin compiler daemon to save memory — 7 GB for Windows and Ubuntu hosts.
+      gradleArgs: --scan "-Dkotlin.compiler.execution.strategy=in-process" # --no-daemon
+      isMac: ${{ startsWith(matrix.os, 'macos') }}
+      isWindows: ${{ startsWith(matrix.os, 'windows') }}
+      isUbuntu: ${{ startsWith(matrix.os, 'ubuntu') }}
+      isUnix: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
     steps:
       - uses: actions/checkout@v2
-      - name: Checkout submodules
-        run: git submodule update --init --recursive
+      - run: git submodule update --init --recursive
 
-      - name: Setup JDK 11
-        uses: actions/setup-java@v2
+      - uses: actions/setup-java@v2
         with:
           distribution: 'adopt'
           java-version: '11'
 
-      - name: chmod -R 777 *
+      - if: ${{ env.isUnix == 'true' }}
         run: chmod -R 777 *
 
-      - name: Init gradle project
-        run: ./gradlew clean --scan
+      # Prepare environment for linking for macOS
 
-      - name: Build all
-        run: ./gradlew assemble --scan
+      - if: ${{ env.isMac == 'true' }}
+        name: Install OpenSSL
+        run: >
+          git clone https://github.com/openssl/openssl.git --recursive &&
+          cd openssl &&
+          git checkout tags/openssl-3.0.3 &&
+          ./Configure --prefix=/opt/openssl --openssldir=/usr/local/ssl &&
+          make &&
+          sudo make install
+
+      - if: ${{ env.isMac == 'true' }}
+        name: Install gcc-multilib
+        run: sudo apt install gcc-multilib -y
+        continue-on-error: true
+
+      # Prepare environment for linking for Ubuntu
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: Install OpenSSL
+        run: sudo apt install libssl-dev -y
+
+      # Prepare environment for linking for Windows
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: Add MSVC to PATH
+        run: 'echo "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.32.31326\bin\Hostx64\x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append'
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: Add LLVM to PATH
+        run: 'echo "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append'
 
-      - name: All Tests
+      # Why using no-asm: https://stackoverflow.com/questions/40007633/how-to-compile-openssl-on-windows
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: Install OpenSSL
         run: >
-          ./gradlew check --scan
-          "-Dmirai.network.show.all.components=true"
-          "-Dkotlinx.coroutines.debug=on"
-          "-Dmirai.network.show.packet.details=true"
+          git clone https://github.com/openssl/openssl.git --recursive &&
+          cd openssl &&
+          git checkout tags/openssl-3.0.3 &&
+          perl Configure VC-WIN64A --prefix=C:/openssl --openssldir=C:/openssl/ssl no-asm &&
+          "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 && 
+          nmake && 
+          nmake install
+        shell: cmd
 
-      - name: Ensure KDoc valid
-        run: ./gradlew dokkaHtmlMultiModule
+      #      - if: ${{ env.isWindows == 'true' }}
+      #        name: Install OpenSSL install_sw
+      #        run: >
+      #          "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 &&
+      #          nmake install_sw
+      #        shell: cmd
+      #        working-directory: openssl
+      #        continue-on-error: true
+
+
+      - name: Clean and download dependencies
+        run: ./gradlew clean ${{ env.gradleArgs }}
+
+      # Linker can use up to 5G memory. We have to do them separately.
+      # Crosslink is not enabled (no libraries on CI)
+
+
+      #######################################################################
+      ############# GENERATED FROM generate-build-native.ws.kts #############
+      #######################################################################
+
+      - name: "Commonize mirai-core-utils"
+        run: ./gradlew :mirai-core-utils:commonize ${{ env.gradleArgs }}
+
+      - name: "Commonize mirai-core-api"
+        run: ./gradlew :mirai-core-api:commonize ${{ env.gradleArgs }}
+
+      - name: "Commonize mirai-core"
+        run: ./gradlew :mirai-core:commonize ${{ env.gradleArgs }}
+
+      # mirai-core-utils
+
+      - name: "Compile mirai-core-utils for common"
+        run: ./gradlew :mirai-core-utils:compileCommonMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-utils for native"
+        run: ./gradlew :mirai-core-utils:compileNativeMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-utils for unix-like"
+        run: ./gradlew :mirai-core-utils:compileUnixMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Compile mirai-core-utils for macosX64"
+        run: ./gradlew :mirai-core-utils:compileKotlinMacosX64 :mirai-core-utils:compileTestKotlinMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Link mirai-core-utils for macosX64"
+        run: ./gradlew mirai-core-utils:linkDebugTestMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Test mirai-core-utils for macosX64"
+        run: ./gradlew :mirai-core-utils:macosX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Compile mirai-core-utils for mingwX64"
+        run: ./gradlew :mirai-core-utils:compileKotlinMingwX64 :mirai-core-utils:compileTestKotlinMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Link mirai-core-utils for mingwX64"
+        run: ./gradlew mirai-core-utils:linkReleaseTestMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Test mirai-core-utils for mingwX64"
+        run: ./gradlew :mirai-core-utils:mingwX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Compile mirai-core-utils for linuxX64"
+        run: ./gradlew :mirai-core-utils:compileKotlinLinuxX64 :mirai-core-utils:compileTestKotlinLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Link mirai-core-utils for linuxX64"
+        run: ./gradlew mirai-core-utils:linkDebugTestLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Test mirai-core-utils for linuxX64"
+        run: ./gradlew :mirai-core-utils:linuxX64Test ${{ env.gradleArgs }}
+
+
+
+      # mirai-core-api
+
+      - name: "Compile mirai-core-api for common"
+        run: ./gradlew :mirai-core-api:compileCommonMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-api for native"
+        run: ./gradlew :mirai-core-api:compileNativeMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-api for unix-like"
+        run: ./gradlew :mirai-core-api:compileUnixMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Compile mirai-core-api for macosX64"
+        run: ./gradlew :mirai-core-api:compileKotlinMacosX64 :mirai-core-api:compileTestKotlinMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Link mirai-core-api for macosX64"
+        run: ./gradlew mirai-core-api:linkDebugTestMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Test mirai-core-api for macosX64"
+        run: ./gradlew :mirai-core-api:macosX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Compile mirai-core-api for mingwX64"
+        run: ./gradlew :mirai-core-api:compileKotlinMingwX64 :mirai-core-api:compileTestKotlinMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Link mirai-core-api for mingwX64"
+        run: ./gradlew mirai-core-api:linkReleaseTestMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Test mirai-core-api for mingwX64"
+        run: ./gradlew :mirai-core-api:mingwX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Compile mirai-core-api for linuxX64"
+        run: ./gradlew :mirai-core-api:compileKotlinLinuxX64 :mirai-core-api:compileTestKotlinLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Link mirai-core-api for linuxX64"
+        run: ./gradlew mirai-core-api:linkDebugTestLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Test mirai-core-api for linuxX64"
+        run: ./gradlew :mirai-core-api:linuxX64Test ${{ env.gradleArgs }}
+
+
+
+      # mirai-core
+
+      - name: "Compile mirai-core for common"
+        run: ./gradlew :mirai-core:compileCommonMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core for native"
+        run: ./gradlew :mirai-core:compileNativeMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core for unix-like"
+        run: ./gradlew :mirai-core:compileUnixMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Compile mirai-core for macosX64"
+        run: ./gradlew :mirai-core:compileKotlinMacosX64 :mirai-core:compileTestKotlinMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Link mirai-core for macosX64"
+        run: ./gradlew mirai-core:linkDebugTestMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Test mirai-core for macosX64"
+        run: ./gradlew :mirai-core:macosX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Compile mirai-core for mingwX64"
+        run: ./gradlew :mirai-core:compileKotlinMingwX64 :mirai-core:compileTestKotlinMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Link mirai-core for mingwX64"
+        run: ./gradlew mirai-core:linkReleaseTestMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Test mirai-core for mingwX64"
+        run: ./gradlew :mirai-core:mingwX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Compile mirai-core for linuxX64"
+        run: ./gradlew :mirai-core:compileKotlinLinuxX64 :mirai-core:compileTestKotlinLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Link mirai-core for linuxX64"
+        run: ./gradlew mirai-core:linkDebugTestLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Test mirai-core for linuxX64"
+        run: ./gradlew :mirai-core:linuxX64Test ${{ env.gradleArgs }}
+
+      #######################################################################
+
+
+
+  build-mirai-core-ubuntu:
+    name: "core-native (${{ matrix.os }})"
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os:
+          - ubuntu-20.04
+          - ubuntu-18.04
+    env:
+      # Disable Gradle daemon and Kotlin compiler daemon to save memory — 7 GB for Windows and Ubuntu hosts.
+      gradleArgs: --scan "-Dkotlin.compiler.execution.strategy=in-process" "-Dmirai.windows.target=false" # Disable windows targets
+      isMac: ${{ startsWith(matrix.os, 'macos') }}
+      isWindows: ${{ startsWith(matrix.os, 'windows') }}
+      isUbuntu: ${{ startsWith(matrix.os, 'ubuntu') }}
+      isUnix: ${{ startsWith(matrix.os, 'macos') || startsWith(matrix.os, 'ubuntu') }}
+    steps:
+      - uses: actions/checkout@v2
+      - run: git submodule update --init --recursive
+
+      - uses: actions/setup-java@v2
+        with:
+          distribution: 'adopt'
+          java-version: '11'
+
+      - if: ${{ env.isUnix == 'true' }}
+        run: chmod -R 777 *
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: Install OpenSSL
+        run: sudo apt install libssl-dev -y
+
+      - if: ${{ env.isUnix == 'true' }}
+        name: Install gcc-multilib
+        run: sudo apt install gcc-multilib -y
+        continue-on-error: true
+
+      - name: Clean and download dependencies
+        run: ./gradlew clean ${{ env.gradleArgs }}
+
+      # Linker can use up to 5G memory. We have to do them separately.
+      # Crosslink is not enabled (no libraries on CI)
+
+      #######################################################################
+      ############# GENERATED FROM generate-build-native.ws.kts #############
+      #######################################################################
+
+      - name: "Commonize mirai-core-utils"
+        run: ./gradlew :mirai-core-utils:commonize ${{ env.gradleArgs }}
+
+      - name: "Commonize mirai-core-api"
+        run: ./gradlew :mirai-core-api:commonize ${{ env.gradleArgs }}
+
+      - name: "Commonize mirai-core"
+        run: ./gradlew :mirai-core:commonize ${{ env.gradleArgs }}
+
+      # mirai-core-utils
+
+      - name: "Compile mirai-core-utils for common"
+        run: ./gradlew :mirai-core-utils:compileCommonMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-utils for native"
+        run: ./gradlew :mirai-core-utils:compileNativeMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-utils for unix-like"
+        run: ./gradlew :mirai-core-utils:compileUnixMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Compile mirai-core-utils for macosX64"
+        run: ./gradlew :mirai-core-utils:compileKotlinMacosX64 :mirai-core-utils:compileTestKotlinMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Link mirai-core-utils for macosX64"
+        run: ./gradlew mirai-core-utils:linkDebugTestMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Test mirai-core-utils for macosX64"
+        run: ./gradlew :mirai-core-utils:macosX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Compile mirai-core-utils for mingwX64"
+        run: ./gradlew :mirai-core-utils:compileKotlinMingwX64 :mirai-core-utils:compileTestKotlinMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Link mirai-core-utils for mingwX64"
+        run: ./gradlew mirai-core-utils:linkDebugTestMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Test mirai-core-utils for mingwX64"
+        run: ./gradlew :mirai-core-utils:mingwX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Compile mirai-core-utils for linuxX64"
+        run: ./gradlew :mirai-core-utils:compileKotlinLinuxX64 :mirai-core-utils:compileTestKotlinLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Link mirai-core-utils for linuxX64"
+        run: ./gradlew mirai-core-utils:linkDebugTestLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Test mirai-core-utils for linuxX64"
+        run: ./gradlew :mirai-core-utils:linuxX64Test ${{ env.gradleArgs }}
+
+
+
+      # mirai-core-api
+
+      - name: "Compile mirai-core-api for common"
+        run: ./gradlew :mirai-core-api:compileCommonMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-api for native"
+        run: ./gradlew :mirai-core-api:compileNativeMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core-api for unix-like"
+        run: ./gradlew :mirai-core-api:compileUnixMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Compile mirai-core-api for macosX64"
+        run: ./gradlew :mirai-core-api:compileKotlinMacosX64 :mirai-core-api:compileTestKotlinMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Link mirai-core-api for macosX64"
+        run: ./gradlew mirai-core-api:linkDebugTestMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Test mirai-core-api for macosX64"
+        run: ./gradlew :mirai-core-api:macosX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Compile mirai-core-api for mingwX64"
+        run: ./gradlew :mirai-core-api:compileKotlinMingwX64 :mirai-core-api:compileTestKotlinMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Link mirai-core-api for mingwX64"
+        run: ./gradlew mirai-core-api:linkDebugTestMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Test mirai-core-api for mingwX64"
+        run: ./gradlew :mirai-core-api:mingwX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Compile mirai-core-api for linuxX64"
+        run: ./gradlew :mirai-core-api:compileKotlinLinuxX64 :mirai-core-api:compileTestKotlinLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Link mirai-core-api for linuxX64"
+        run: ./gradlew mirai-core-api:linkDebugTestLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Test mirai-core-api for linuxX64"
+        run: ./gradlew :mirai-core-api:linuxX64Test ${{ env.gradleArgs }}
+
+
+
+      # mirai-core
+
+      - name: "Compile mirai-core for common"
+        run: ./gradlew :mirai-core:compileCommonMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core for native"
+        run: ./gradlew :mirai-core:compileNativeMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - name: "Compile mirai-core for unix-like"
+        run: ./gradlew :mirai-core:compileUnixMainKotlinMetadata ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Compile mirai-core for macosX64"
+        run: ./gradlew :mirai-core:compileKotlinMacosX64 :mirai-core:compileTestKotlinMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Link mirai-core for macosX64"
+        run: ./gradlew mirai-core:linkDebugTestMacosX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isMac == 'true' }}
+        name: "Test mirai-core for macosX64"
+        run: ./gradlew :mirai-core:macosX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Compile mirai-core for mingwX64"
+        run: ./gradlew :mirai-core:compileKotlinMingwX64 :mirai-core:compileTestKotlinMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Link mirai-core for mingwX64"
+        run: ./gradlew mirai-core:linkDebugTestMingwX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isWindows == 'true' }}
+        name: "Test mirai-core for mingwX64"
+        run: ./gradlew :mirai-core:mingwX64Test ${{ env.gradleArgs }}
+
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Compile mirai-core for linuxX64"
+        run: ./gradlew :mirai-core:compileKotlinLinuxX64 :mirai-core:compileTestKotlinLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Link mirai-core for linuxX64"
+        run: ./gradlew mirai-core:linkDebugTestLinuxX64 ${{ env.gradleArgs }}
+
+      - if: ${{ env.isUbuntu == 'true' }}
+        name: "Test mirai-core for linuxX64"
+        run: ./gradlew :mirai-core:linuxX64Test ${{ env.gradleArgs }}
+
+      #######################################################################
 
-      - name: Upload build artifacts
-        uses: ./.github/actions/upload-build-artifacts

+ 1 - 1
.github/workflows/doc.yml

@@ -8,7 +8,7 @@ on:
 
 jobs:
   mirai-docs:
-    runs-on: ubuntu-latest
+    runs-on: macos-12 # 14G memory
     steps:
       - name: Checkout repository
         uses: actions/checkout@v2

+ 1 - 1
.github/workflows/release.yml

@@ -7,7 +7,7 @@ on:
 
 jobs:
   publish-mirai:
-    runs-on: ubuntu-latest
+    runs-on: macos-12 # 14G memory
     steps:
       - name: Checkout repository
         uses: actions/checkout@v2

+ 2 - 2
.github/workflows/snapshots.yml

@@ -11,7 +11,7 @@ on:
 
 jobs:
   publish-mirai:
-    runs-on: ubuntu-latest
+    runs-on: macos-12 # 14G memory
     steps:
       - uses: actions/checkout@v2
       - run: git submodule update --init --recursive
@@ -46,7 +46,7 @@ jobs:
           -Dmirai.network.handle.selector.logging=true
 
       - run: >
-          ./gradlew publish --info --scan
+          ./gradlew publish --no-parallel --info --scan
         env:
           MIRAI_IS_SNAPSHOTS_PUBLISHING: true
           SNAPSHOTS_PUBLISHING_USER: ${{ secrets.SNAPSHOTS_PUBLISHING_USER }}

+ 2 - 1
buildSrc/src/main/kotlin/HmppConfigure.kt

@@ -30,6 +30,7 @@ private val miraiPlatform = Attribute.of(
 )
 
 val IDEA_ACTIVE = System.getProperty("idea.active") == "true" && System.getProperty("publication.test") != "true"
+val WINDOWS_TARGET_ENABLED = System.getProperty("mirai.windows.target") != "false"
 
 val NATIVE_ENABLED = System.getProperty("mirai.enable.native", "true").toBoolean()
 val ANDROID_ENABLED = System.getProperty("mirai.enable.android", "true").toBoolean()
@@ -80,7 +81,7 @@ val MAC_TARGETS: Set<String> by lazy {
     )
 }
 
-val WIN_TARGETS = setOf("mingwX64")
+val WIN_TARGETS = if (WINDOWS_TARGET_ENABLED) setOf("mingwX64") else emptySet()
 
 val LINUX_TARGETS = setOf("linuxX64")
 

+ 1 - 1
gradle.properties

@@ -9,7 +9,7 @@
 kotlin.code.style=official
 # config
 kotlin.incremental.multiplatform=true
-org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8 --illegal-access=permit -Dkotlin.daemon.jvm.options=--illegal-access=permit --add-opens java.base/java.util=ALL-UNNAMED
+org.gradle.jvmargs=-Xmx6000m -Dfile.encoding=UTF-8 --illegal-access=permit -Dkotlin.daemon.jvm.options=--illegal-access=permit --add-opens java.base/java.util=ALL-UNNAMED
 org.gradle.parallel=true
 org.gradle.vfs.watch=true
 kotlin.mpp.enableGranularSourceSetsMetadata=true

+ 0 - 10
mirai-core-utils/build.gradle.kts

@@ -75,16 +75,6 @@ kotlin {
 //                implementation("com.soywiz.korlibs.krypto:krypto:2.4.12") // ':mirai-core-utils:compileNativeMainKotlinMetadata' fails because compiler cannot find reference
             }
         }
-
-        val mingwX64Main by getting {
-            dependencies {
-            }
-        }
-
-        val unixMain by getting {
-            dependencies {
-            }
-        }
     }
 }
 

+ 40 - 3
mirai-core/build.gradle.kts

@@ -11,6 +11,8 @@
 
 import BinaryCompatibilityConfigurator.configureBinaryValidators
 import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
+import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
+import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest
 
 plugins {
     kotlin("multiplatform")
@@ -106,12 +108,25 @@ kotlin {
             }
         }
 
-        NATIVE_TARGETS.forEach { target ->
-            (targets.getByName(target) as KotlinNativeTarget).compilations.getByName("main").cinterops.create("OpenSSL")
+        NATIVE_TARGETS.forEach { targetName ->
+            val defFile = projectDir.resolve("src/nativeMain/cinterop/OpenSSL.def")
+            val target = targets.getByName(targetName) as KotlinNativeTarget
+            target.compilations.getByName("main").cinterops.create("OpenSSL")
                 .apply {
-                    defFile = projectDir.resolve("src/nativeMain/cinterop/OpenSSL.def")
+                    this.defFile = defFile
                     packageName("openssl")
                 }
+
+            if (!IDEA_ACTIVE && HOST_KIND == HostKind.WINDOWS) {
+                target.binaries.test(listOf(NativeBuildType.RELEASE)) {
+                    // add release test to run on CI
+                    afterEvaluate {
+                        // use linkReleaseTestMingwX64 for mingwX64Test to save memory
+                        tasks.getByName("mingwX64Test", KotlinNativeTest::class)
+                            .executable(linkTask) { linkTask.binary.outputFile }
+                    }
+                }
+            }
         }
 
         UNIX_LIKE_TARGETS.forEach { target ->
@@ -149,6 +164,28 @@ kotlin {
     }
 }
 
+afterEvaluate {
+    val main = projectDir.resolve("src/nativeTest/kotlin/local/TestMain.kt")
+    if (!main.exists()) {
+        main.writeText(
+            """
+            /*
+             * Copyright 2019-2022 Mamoe Technologies and contributors.
+             *
+             * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+             * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+             *
+             * https://github.com/mamoe/mirai/blob/dev/LICENSE
+             */
+
+            package net.mamoe.mirai.internal.local
+
+            fun main() {}
+        """.trimIndent()
+        )
+    }
+}
+
 if (isAndroidSDKAvailable) {
     tasks.register("checkAndroidApiLevel") {
         doFirst {

+ 21 - 30
mirai-core/src/nativeMain/cinterop/OpenSSL.def

@@ -1,43 +1,34 @@
 headers = openssl/ec.h openssl/ecdh.h openssl/evp.h
 
-linkerOpts.osx =             -lcrypto \
+# -L/usr/local/opt/[email protected]/1.1.1o/lib  is for GitHub actions. See https://github.com/actions/virtual-environments/blob/main/images/macos/macos-12-Readme.md
+
+linkerOpts =                 -lcrypto \
                              -lssl \
+                             -L/opt/openssl/lib64 \
                              -L/opt/openssl/lib \
+                             -L/usr/local/opt/[email protected]/1.1.1o/lib \
+                             -L/usr/lib/[email protected]/1.1.1o/lib \
+                             -L/opt/homebrew/Cellar/[email protected]/1.1.1o/lib \
                              -L/opt/homebrew/Cellar/openssl@3/3.0.3/lib \
                              -L/opt/homebrew/opt/openssl@3/lib \
-
-compilerOpts.osx =           -I/opt/openssl/include \
-                             -I/usr/local/include/openssl@3 \
-                             -I/opt/homebrew/Cellar/openssl@3/3.0.3/include \
-                             -I/usr/include/openssl@3 \
-                             -I/opt/homebrew/opt/openssl@3/include
-
-linkerOpts.linux =           -lcrypto \
-                             -lssl \
+                             -L/usr/lib/ \
+                             -LC:/openssl/lib \
+                             \
                              -L/usr/lib64 \
                              -L/usr/lib/x86_64-linux-gnu \
                              -L/opt/local/lib \
-                             -L/usr/local/opt/openssl@3/lib \
-                             -L/opt/homebrew/opt/openssl@3/lib
-
-compilerOpts.linux =         -I/opt/local/include/openssl@3 \
-                             -I/usr/bin/openssl@3 \
-                             -I/usr/local/include/openssl@3 \
-                             -I/usr/include/openssl@3 \
-                             -I/opt/homebrew/opt/openssl@3/include
+                             -L/usr/local/opt/curl/lib \
+                             -L/opt/homebrew/opt/curl/lib
 
-linkerOpts.mingw_x64 =       -lcrypto \
-                             -lssl \
-                             -L/usr/lib64 \
-                             -L/usr/lib/x86_64-linux-gnu \
-                             -L/opt/local/lib \
-                             -L/usr/local/opt/openssl@3/lib \
-                             -L/opt/homebrew/opt/openssl@3/lib \
-                             -LC:/Tools/msys64/mingw64/lib \
-                             -LC:/Tools/msys2/mingw64/lib
 
-compilerOpts.mingw_x64 =     -I/opt/local/include/openssl@3 \
-                             -I/usr/bin/openssl@3 \
+compilerOpts =               -I/opt/openssl/include \
                              -I/usr/local/include/openssl@3 \
+                             -I/usr/local/opt/[email protected]/1.1.1o/include \
+                             -I/opt/homebrew/Cellar/[email protected]/1.1.1o/include \
+                             -I/opt/homebrew/Cellar/openssl@3/3.0.3/include \
                              -I/usr/include/openssl@3 \
-                             -I/opt/homebrew/opt/openssl@3/include
+                             -I/opt/homebrew/opt/openssl@3/include \
+                             -I/usr/include/ \
+                             -I/usr/include/x86_64-linux-gnu/ \
+                             -I/usr/local/include/ \
+                             -IC:/openssl/include/ \

+ 2 - 1
mirai-core/src/nativeTest/kotlin/local/TestMain.kt.template

@@ -22,7 +22,8 @@ suspend fun main() {
     val bot = BotFactory.newBot(12346, "") {
         enableContactCache()
         protocol = BotConfiguration.MiraiProtocol.ANDROID_PAD
-        workingDir = "test/run"
+        workingDir = "test-sandbox/native-run" // Will be based on $rootProject/mirai-core
+        fileBasedDeviceInfo("local.device.json")
     }
 
     bot.login()