Skip to content

Commit

Permalink
Try fix cross-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
hans00 committed Apr 24, 2024
1 parent e05e279 commit 14e952e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
41 changes: 31 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,45 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
- run: yarn install
- name: Build CPU (x86_64)
run: yarn clean && yarn build-native
- name: Build CPU (arm64)
run: yarn clean && yarn build-native -A arm64
- name: Prepare Toolchain (Linux)
if: runner.os == 'linux-latest'
run: |
sudo apt-get update
sudo apt-get install -qy binutils-aarch64-linux-gnu gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Prepare Vulkan SDK
if: runner.os == 'ubuntu-latest'
uses: humbletim/[email protected]
with:
vulkan-query-version: 1.3.204.0
vulkan-components: Vulkan-Headers, Vulkan-Loader
vulkan-use-cache: true
- name: Build with Vulkan
if: runner.os == 'ubuntu-latest'
run: yarn clean && yarn build-native --CDVARIANT=vulkan --CDLLAMA_VULKAN=1
- name: Build with OpenCL
- uses: Jimver/[email protected]
id: cuda-toolkit
if: runner.os != 'macos-latest'
with:
cuda: '11.8.0'
- name: Prepare OpenCL SDK
if: runner.os == 'windows-latest'
run: |
wget https://github.com/KhronosGroup/OpenCL-SDK/releases/download/v2023.12.14/OpenCL-SDK-v2023.12.14-Win-x64.zip
unzip OpenCL-SDK-v2023.12.14-Win-x64.zip -d OpenCL-SDK
- name: Install dependencies
run: yarn install
- name: Build (Linux)
if: runner.os == 'linux-latest'
run: |
yarn clean && yarn build-native -a x86_64 --CDLLAMA_CUDA=1
yarn clean && yarn build-native -a aarch64 --cc aarch64-linux-gnu-gcc --cxx aarch64-linux-gnu-g++ --CDLLAMA_CLBLAST=1 --CDCLBlast_DIR=OpenCL-SDK
- name: Build (Windows)
if: runner.os == 'windows-latest'
run: yarn clean && yarn build-native --CDVARIANT=opencl --CDLLAMA_OPENCL=1
run: |
yarn clean && yarn build-native -a x86_64 --CDLLAMA_CUDA=1
yarn clean && yarn build-native -a x86_64 --CDLLAMA_CLBLAST=1 --CDCLBlast_DIR=OpenCL-SDK
- name: Build (macOS)
if: runner.os == 'macos-latest'
run: |
yarn clean && yarn build-native -a x86_64
yarn clean && yarn build-native -a aarch64
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ endif()
add_definitions(-DNAPI_VERSION=${napi_build_version})
message(STATUS "NAPI_VERSION: ${napi_build_version}")

# default build Release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_SYSTEM_PROCESSOR ${NODE_ARCH})
string(TOLOWER ${CMAKE_SYSTEM_NAME} PLATFORM)
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} ARCH)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "To Platform: ${CMAKE_SYSTEM_NAME}")
message(STATUS "To Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "Platform: ${PLATFORM}")
message(STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR}")

# set strip flags
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(UNIX OR MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s")
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /s")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /s")
endif()
endif()

include_directories(${CMAKE_JS_INC})

Expand All @@ -36,8 +46,6 @@ target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
# static link llama and ggml
target_link_libraries(${PROJECT_NAME} PUBLIC llama ggml common)

string(TOLOWER ${CMAKE_SYSTEM_NAME} PLATFORM)
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} ARCH)
string(REPLACE "amd64" "x64" ARCH ${ARCH})
string(REPLACE "x86_64" "x64" ARCH ${ARCH})
string(REPLACE "i686" "x86" ARCH ${ARCH})
Expand All @@ -46,10 +54,12 @@ string(REPLACE "arm" "arm" ARCH ${ARCH})
string(REPLACE "aarch64" "arm64" ARCH ${ARCH})

if(DEFINED VARIANT)
string(APPEND PLATFORM "-${VARIANT}")
set(VARIANT -${VARIANT})
else()
set(VARIANT "")
endif()

set(PLATFORM_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin/${PLATFORM}/${ARCH})
set(PLATFORM_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin/${PLATFORM}${VARIANT}/${ARCH})
message(STATUS "PLATFORM_BINARY_DIR: ${PLATFORM_BINARY_DIR}")

if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
Expand Down

0 comments on commit 14e952e

Please sign in to comment.