Jelajahi Sumber

Support RISC-V (#213)

Fangjun Kuang 2 tahun lalu
induk
melakukan
f9a850c725
2 mengubah file dengan 69 tambahan dan 0 penghapusan
  1. 52 0
      build-riscv64-linux-gnu.sh
  2. 17 0
      toolchains/riscv64-linux-gnu.toolchain.cmake

+ 52 - 0
build-riscv64-linux-gnu.sh

@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+if ! command -v riscv64-linux-gnu-g++  &> /dev/null; then
+  echo "Please install the toolchain first."
+  echo
+  echo "You can use the following command to install the toolchain:"
+  echo
+  echo "  sudo apt-get install gcc-riscv64-linux-gnu"
+  echo "  sudo apt-get install g++-riscv64-linux-gnu"
+  echo
+  exit 1
+fi
+
+dir=build-riscv64-linux-gnu
+mkdir -p $dir
+cd $dir
+
+if [ ! -f alsa-lib/src/.libs/libasound.so ]; then
+  echo "Start to cross-compile alsa-lib"
+  if [ ! -d alsa-lib ]; then
+    git clone --depth 1 https://github.com/alsa-project/alsa-lib
+  fi
+  # If it shows:
+  #  ./gitcompile: line 79: libtoolize: command not found
+  # Please use:
+  #  sudo apt-get install libtool m4 automake
+  #
+  pushd alsa-lib
+  CC=riscv64-linux-gnu-gcc ./gitcompile --host=riscv64-linux-gnu
+  popd
+  echo "Finish cross-compiling alsa-lib"
+fi
+
+export CPLUS_INCLUDE_PATH=$PWD/alsa-lib/include:$CPLUS_INCLUDE_PATH
+export SHERPA_NCNN_ALSA_LIB_DIR=$PWD/alsa-lib/src/.libs
+
+cmake \
+  -DCMAKE_INSTALL_PREFIX=./install \
+  -DCMAKE_BUILD_TYPE=Release \
+  -DBUILD_SHARED_LIBS=OFF \
+  -DSHERPA_NCNN_ENABLE_PYTHON=OFF \
+  -DSHERPA_NCNN_ENABLE_PORTAUDIO=OFF \
+  -DSHERPA_NCNN_ENABLE_JNI=OFF \
+  -DSHERPA_NCNN_ENABLE_BINARY=ON \
+  -DSHERPA_NCNN_ENABLE_TEST=OFF \
+  -DCMAKE_TOOLCHAIN_FILE=../toolchains/riscv64-linux-gnu.toolchain.cmake \
+  ..
+
+make VERBOSE=1 -j4
+make install/strip
+
+cp -v $SHERPA_NCNN_ALSA_LIB_DIR/libasound.so* ./install/lib/

+ 17 - 0
toolchains/riscv64-linux-gnu.toolchain.cmake

@@ -0,0 +1,17 @@
+# Copied from https://github.com/Tencent/ncnn/blob/master/toolchains/riscv64-linux-gnu.toolchain.cmake
+set(CMAKE_SYSTEM_NAME Linux)
+set(CMAKE_SYSTEM_PROCESSOR riscv64)
+
+set(CMAKE_C_COMPILER "riscv64-linux-gnu-gcc")
+set(CMAKE_CXX_COMPILER "riscv64-linux-gnu-g++")
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+set(CMAKE_C_FLAGS "-march=rv64gc")
+set(CMAKE_CXX_FLAGS "-march=rv64gc")
+
+# cache flags
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")