Просмотр исходного кода

Add Windows wamrc and iwasm build in release CI (#3857)

- For Windows, llvm libs need to cache more directories, so use a multi-line
  environment variable for paths
- Remove conditionally build directories `win32build`, just use `build` for all platform
- Add Windows wamrc and iwasm(disable lib pthread semaphore and fast jit for now)
  build in release CI
TianlongLiang 1 год назад
Родитель
Сommit
1af474099b

+ 11 - 1
.github/workflows/build_iwasm_release.yml

@@ -51,6 +51,7 @@ jobs:
           fail-on-cache-miss: true
           fail-on-cache-miss: true
 
 
       - name: generate iwasm binary release
       - name: generate iwasm binary release
+        shell: bash
         run: |
         run: |
           cmake -S . -B build \
           cmake -S . -B build \
             -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \
             -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 \
@@ -81,7 +82,16 @@ jobs:
           cmake --build build --config Release --parallel 4
           cmake --build build --config Release --parallel 4
         working-directory: ${{ inputs.cwd }}
         working-directory: ${{ inputs.cwd }}
 
 
-      - name: compress the binary
+      - name: Compress the binary on Windows
+        if: inputs.runner == 'windows-latest'
+        run: |
+          tar -czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm.exe
+          Compress-Archive -Path iwasm.exe -DestinationPath iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
+          mv iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
+        working-directory: ${{ inputs.cwd }}/build/Release
+
+      - name: compress the binary on non-Windows
+        if: inputs.runner != 'windows-latest'
         run: |
         run: |
           tar czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm
           tar czf iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz iwasm
           zip iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm
           zip iwasm-${{ inputs.ver_num }}-${{ inputs.runner }}.zip iwasm

+ 23 - 4
.github/workflows/build_llvm_libraries.yml

@@ -43,6 +43,7 @@ jobs:
 
 
       - name: install dependencies for non macos-14
       - name: install dependencies for non macos-14
         if: inputs.os != 'macos-14'
         if: inputs.os != 'macos-14'
+        shell: bash
         run: /usr/bin/env python3 -m pip install -r requirements.txt
         run: /usr/bin/env python3 -m pip install -r requirements.txt
         working-directory: build-scripts
         working-directory: build-scripts
 
 
@@ -51,10 +52,13 @@ jobs:
         run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
         run: /usr/bin/env python3 -m pip install -r requirements.txt --break-system-packages
         working-directory: build-scripts
         working-directory: build-scripts
 
 
-      - name: retrieve the last commit ID
+      - name: Retrieve the last commit ID
         id: get_last_commit
         id: get_last_commit
-        run: echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT
-        working-directory: build-scripts
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        shell: bash
+        run: |
+          echo "last_commit=$(GH_TOKEN=${{ secrets.GITHUB_TOKEN }} /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --llvm-ver)" >> $GITHUB_OUTPUT
 
 
       # Bump the prefix number to evict all previous caches and
       # Bump the prefix number to evict all previous caches and
       # enforce a clean build, in the unlikely case that some
       # enforce a clean build, in the unlikely case that some
@@ -62,7 +66,9 @@ jobs:
       # suspect.
       # suspect.
       - name: form the cache key of libraries
       - name: form the cache key of libraries
         id: create_lib_cache_key
         id: create_lib_cache_key
-        run: echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
+        shell: bash
+        run: |
+          echo "key=0-llvm-libraries-${{ inputs.os }}-${{ inputs.arch }}-${{ steps.get_last_commit.outputs.last_commit }}${{ inputs.cache_key_suffix }}" >> $GITHUB_OUTPUT
 
 
       - name: Cache LLVM libraries
       - name: Cache LLVM libraries
         id: retrieve_llvm_libs
         id: retrieve_llvm_libs
@@ -107,7 +113,20 @@ jobs:
       - run: brew install ccache ninja
       - run: brew install ccache ninja
         if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
         if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && startsWith(inputs.os, 'macos')
 
 
+      - uses: actions/cache@v4
+        with:
+          path: ~/.cache/ccache
+          key: 0-ccache-${{ inputs.os }}-${{ steps.get_last_commit.outputs.last_commit }}
+          restore-keys: |
+            0-ccache-${{ inputs.os }}
+        if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
+
+      # Install tools on Windows
+      - run: choco install -y ccache ninja
+        if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true' && inputs.os == 'windows-latest'
+
       - name: Build LLVM libraries
       - name: Build LLVM libraries
         if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
         if: steps.retrieve_llvm_libs.outputs.cache-hit != 'true'
+        shell: bash
         run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
         run: /usr/bin/env python3 ./build_llvm.py ${{ inputs.extra_build_llvm_options }} --arch ${{ inputs.arch }}
         working-directory: build-scripts
         working-directory: build-scripts

+ 10 - 2
.github/workflows/build_wamrc.yml

@@ -56,8 +56,16 @@ jobs:
           cmake --build build --config Release --parallel 4
           cmake --build build --config Release --parallel 4
         working-directory: wamr-compiler
         working-directory: wamr-compiler
 
 
-      - name: compress the binary
-        if: inputs.release
+      - name: Compress the binary on Windows
+        if: inputs.runner == 'windows-latest' && inputs.release
+        run: |
+          tar -czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc.exe
+          Compress-Archive -Path wamrc.exe -DestinationPath wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip
+          mv wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.* ../
+        working-directory: wamr-compiler/build/Release
+
+      - name: compress the binary on non-Windows
+        if: inputs.runner != 'windows-latest' && inputs.release
         run: |
         run: |
           tar czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
           tar czf wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.tar.gz wamrc
           zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc
           zip wamrc-${{ inputs.ver_num }}-${{ inputs.runner }}.zip wamrc

+ 27 - 0
.github/workflows/release_process.yml

@@ -72,6 +72,13 @@ jobs:
       os: "macos-13"
       os: "macos-13"
       arch: "AArch64 ARM Mips RISCV X86"
       arch: "AArch64 ARM Mips RISCV X86"
 
 
+  build_llvm_libraries_on_windows:
+    needs: [create_tag, create_release]
+    uses: ./.github/workflows/build_llvm_libraries.yml
+    with:
+      os: "windows-latest"
+      arch: "AArch64 ARM Mips RISCV X86"
+
   #
   #
   # WAMRC
   # WAMRC
   release_wamrc_on_ubuntu_2004:
   release_wamrc_on_ubuntu_2004:
@@ -103,6 +110,16 @@ jobs:
       runner: macos-13
       runner: macos-13
       upload_url: ${{ needs.create_release.outputs.upload_url }}
       upload_url: ${{ needs.create_release.outputs.upload_url }}
       ver_num: ${{ needs.create_tag.outputs.new_ver }}
       ver_num: ${{ needs.create_tag.outputs.new_ver }}
+  
+  release_wamrc_on_windows:
+    needs: [create_tag, create_release, build_llvm_libraries_on_windows]
+    uses: ./.github/workflows/build_wamrc.yml
+    with:
+      llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}
+      release: true
+      runner: windows-latest
+      upload_url: ${{ needs.create_release.outputs.upload_url }}
+      ver_num: ${{ needs.create_tag.outputs.new_ver }}
 
 
   #
   #
   # IWASM
   # IWASM
@@ -136,6 +153,16 @@ jobs:
       upload_url: ${{ needs.create_release.outputs.upload_url }}
       upload_url: ${{ needs.create_release.outputs.upload_url }}
       ver_num: ${{ needs.create_tag.outputs.new_ver}}
       ver_num: ${{ needs.create_tag.outputs.new_ver}}
 
 
+  release_iwasm_on_windows:
+    needs: [create_tag, create_release, build_llvm_libraries_on_windows]
+    uses: ./.github/workflows/build_iwasm_release.yml
+    with:
+      cwd: product-mini/platforms/windows
+      llvm_cache_key: ${{ needs.build_llvm_libraries_on_windows.outputs.cache_key }}
+      runner: windows-latest
+      upload_url: ${{ needs.create_release.outputs.upload_url }}
+      ver_num: ${{ needs.create_tag.outputs.new_ver}}
+
   #
   #
   # WAMR_SDK
   # WAMR_SDK
   release_wamr_sdk_on_ubuntu_2004:
   release_wamr_sdk_on_ubuntu_2004:

+ 32 - 4
build-scripts/build_llvm.py

@@ -125,9 +125,7 @@ def build_llvm(llvm_dir, platform, backends, projects, use_clang=False, extra_fl
     if not llvm_dir.exists():
     if not llvm_dir.exists():
         raise Exception(f"{llvm_dir} doesn't exist")
         raise Exception(f"{llvm_dir} doesn't exist")
 
 
-    build_dir = llvm_dir.joinpath(
-        "win32build" if "windows" == platform else "build"
-    ).resolve()
+    build_dir = llvm_dir.joinpath("build").resolve()
     build_dir.mkdir(exist_ok=True)
     build_dir.mkdir(exist_ok=True)
 
 
     lib_llvm_core_library = build_dir.joinpath("lib/libLLVMCore.a").resolve()
     lib_llvm_core_library = build_dir.joinpath("lib/libLLVMCore.a").resolve()
@@ -178,6 +176,7 @@ def repackage_llvm(llvm_dir):
         raise Exception("Find more than one LLVM-*.tar.gz")
         raise Exception("Find more than one LLVM-*.tar.gz")
 
 
     if not packs:
     if not packs:
+        raise Exception("Didn't find any LLVM-* package")
         return
         return
 
 
     llvm_package = packs[0].name
     llvm_package = packs[0].name
@@ -193,6 +192,31 @@ def repackage_llvm(llvm_dir):
     # rm ./LLVM-1*.gz
     # rm ./LLVM-1*.gz
     os.remove(llvm_dir.joinpath(llvm_package).resolve())
     os.remove(llvm_dir.joinpath(llvm_package).resolve())
 
 
+def repackage_llvm_windows(llvm_dir):
+    build_dir = llvm_dir.joinpath("./build").resolve()
+
+    packs_path = [f for f in build_dir.glob("./_CPack_Packages/win64/NSIS/LLVM-*-win64")]
+    if len(packs_path) > 1:
+        raise Exception("Find more than one LLVM-* package")
+
+    if not packs_path:
+        raise Exception("Didn't find any LLVM-* package")
+        return
+    
+    llvm_package_path = f"_CPack_Packages/win64/NSIS/{packs_path[0].name}"
+    windows_package_dir = build_dir.joinpath(llvm_package_path).resolve()
+
+    # mv package dir outside of build 
+    shutil.move(str(windows_package_dir), str(llvm_dir))
+    # rm -r build
+    shutil.rmtree(str(build_dir))
+    # mkdir build
+    build_dir.mkdir()
+    # move back all the subdiretories under cpack directory(bin/include/lib) to build dir
+    moved_package_dir = llvm_dir.joinpath(packs_path[0].name)
+    for sub_dir in moved_package_dir.iterdir():
+        shutil.move(str(sub_dir), str(build_dir))
+    moved_package_dir.rmdir()  
 
 
 def main():
 def main():
     parser = argparse.ArgumentParser(description="build necessary LLVM libraries")
     parser = argparse.ArgumentParser(description="build necessary LLVM libraries")
@@ -304,7 +328,11 @@ def main():
             )
             )
             is not None
             is not None
         ):
         ):
-            repackage_llvm(llvm_dir)
+            # TODO: repackage process may change in the future, this work for LLVM 15.x
+            if "windows" == platform:
+                repackage_llvm_windows(llvm_dir)
+            else:
+                repackage_llvm(llvm_dir)
 
 
         return True
         return True
     except subprocess.CalledProcessError:
     except subprocess.CalledProcessError:

+ 0 - 3
build-scripts/config_common.cmake

@@ -102,9 +102,6 @@ if (WAMR_BUILD_JIT EQUAL 1)
   if (NOT DEFINED LLVM_DIR)
   if (NOT DEFINED LLVM_DIR)
     set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
     set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
     set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
     set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build")
-    if (WAMR_BUILD_PLATFORM STREQUAL "windows")
-      set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/win32build")
-    endif ()
     if (NOT EXISTS "${LLVM_BUILD_ROOT}")
     if (NOT EXISTS "${LLVM_BUILD_ROOT}")
         message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
         message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}")
     endif ()
     endif ()

+ 10 - 1
build-scripts/runtime_lib.cmake

@@ -59,7 +59,12 @@ if (WAMR_BUILD_INTERP EQUAL 1)
 endif ()
 endif ()
 
 
 if (WAMR_BUILD_FAST_JIT EQUAL 1)
 if (WAMR_BUILD_FAST_JIT EQUAL 1)
-    include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake)
+    if (WAMR_BUILD_PLATFORM STREQUAL "windows")
+        message ("Fast JIT currently not supported on Windows")
+        set (WAMR_BUILD_FAST_JIT 0)
+    else ()
+        include (${IWASM_DIR}/fast-jit/iwasm_fast_jit.cmake)
+    endif ()
 endif ()
 endif ()
 
 
 if (WAMR_BUILD_JIT EQUAL 1)
 if (WAMR_BUILD_JIT EQUAL 1)
@@ -104,6 +109,10 @@ if (WAMR_BUILD_WASI_NN EQUAL 1)
 endif ()
 endif ()
 
 
 if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
 if (WAMR_BUILD_LIB_PTHREAD EQUAL 1)
+    if (WAMR_BUILD_PLATFORM STREQUAL "windows")
+        set (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 0)
+        message ("Lib pthread semaphore currently not supported on Windows")
+    endif ()
     include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
     include (${IWASM_DIR}/libraries/lib-pthread/lib_pthread.cmake)
     # Enable the dependent feature if lib pthread is enabled
     # Enable the dependent feature if lib pthread is enabled
     set (WAMR_BUILD_THREAD_MGR 1)
     set (WAMR_BUILD_THREAD_MGR 1)

+ 1 - 1
core/iwasm/libraries/lib-pthread/lib_pthread.cmake

@@ -6,7 +6,7 @@ set (LIB_PTHREAD_DIR ${CMAKE_CURRENT_LIST_DIR})
 add_definitions (-DWASM_ENABLE_LIB_PTHREAD=1)
 add_definitions (-DWASM_ENABLE_LIB_PTHREAD=1)
 
 
 if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
 if (WAMR_BUILD_LIB_PTHREAD_SEMAPHORE EQUAL 1)
-add_definitions (-DWASM_ENABLE_LIB_PTHREAD_SEMAPHORE=1)
+    add_definitions (-DWASM_ENABLE_LIB_PTHREAD_SEMAPHORE=1)
 endif()
 endif()
 
 
 include_directories(${LIB_PTHREAD_DIR})
 include_directories(${LIB_PTHREAD_DIR})

+ 3 - 10
wamr-compiler/CMakeLists.txt

@@ -163,17 +163,10 @@ endif()
 # Enable LLVM
 # Enable LLVM
 if (NOT WAMR_BUILD_WITH_CUSTOM_LLVM)
 if (NOT WAMR_BUILD_WITH_CUSTOM_LLVM)
   set (LLVM_SRC_ROOT "${PROJECT_SOURCE_DIR}/../core/deps/llvm")
   set (LLVM_SRC_ROOT "${PROJECT_SOURCE_DIR}/../core/deps/llvm")
-  if (WAMR_BUILD_PLATFORM STREQUAL "windows")
-    if (NOT EXISTS "${LLVM_SRC_ROOT}/win32build")
-      message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/win32build")
-    endif ()
-    set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/win32build;${CMAKE_PREFIX_PATH}")
-  else()
-    if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
-      message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
-    endif ()
-    set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
+  if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
+    message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
   endif ()
   endif ()
+  set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
 endif ()
 endif ()
 
 
 find_package(LLVM REQUIRED CONFIG)
 find_package(LLVM REQUIRED CONFIG)