From 7ef3c615243fd0b9c8ab5d74c4a416c5ac5a00db Mon Sep 17 00:00:00 2001 From: Paulo Valente <16843419+polvalente@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:05:01 -0300 Subject: [PATCH] feat: build host as well --- .github/workflows/embedded_devices.yml | 2 +- Makefile | 7 +++- scripts/build_and_package.sh | 47 +++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/embedded_devices.yml b/.github/workflows/embedded_devices.yml index 35b2e3a..d259641 100644 --- a/.github/workflows/embedded_devices.yml +++ b/.github/workflows/embedded_devices.yml @@ -64,7 +64,7 @@ jobs: if: steps.cache-iree-dir.outputs.cache-hit != 'true' run: make clone_iree - name: Compile - run: ./scripts/build_and_package.sh ${{ matrix.build_target }} + run: ./scripts/build_and_package.sh ${{ matrix.build_target }} --build-host - name: Release Artifacts uses: softprops/action-gh-release@v2 if: startsWith(github.ref, 'refs/tags/') diff --git a/Makefile b/Makefile index de2c3b0..f7ef370 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,8 @@ else ifeq ($(IREE_BUILD_TARGET), ios) -DCMAKE_OSX_ARCHITECTURES=arm64\ -DCMAKE_SYSTEM_PROCESSOR=arm64\ -DCMAKE_IOS_INSTALL_COMBINED=YES\ - -DCMAKE_OSX_SYSROOT=$(shell xcodebuild -version -sdk iphoneos Path) + -DCMAKE_OSX_SYSROOT=$(shell xcodebuild -version -sdk iphoneos Path)\ + -DIREE_HOST_BIN_DIR=$(IREE_HOST_INSTALL_DIR) else ifeq ($(IREE_BUILD_TARGET), ios_simulator) BUILD_TARGET_FLAGS += \ -DCMAKE_SYSTEM_NAME=iOS\ @@ -88,7 +89,11 @@ else endif .PHONY: install_runtime +ifdef IREE_HOST_INSTALL_DIR +install_runtime: $(IREE_HOST_INSTALL_DIR) $(IREE_INSTALL_DIR) +else install_runtime: $(IREE_INSTALL_DIR) +endif CMAKE_SOURCES = cmake/src/runtime.cc cmake/src/runtime.h diff --git a/scripts/build_and_package.sh b/scripts/build_and_package.sh index f48ae4d..c9ac225 100755 --- a/scripts/build_and_package.sh +++ b/scripts/build_and_package.sh @@ -12,17 +12,54 @@ get_nproc() { fi } +# Initialize variable +build_host_flag=false + +# Parse options +while [[ $# -gt 0 ]]; do + case $1 in + --build-host) + build_host_flag=true + shift # Shift past the argument + ;; + *) + echo "Unknown option: $1" + exit 1 + ;; + esac +done + NUM_JOBS=-j$(get_nproc) mkdir -p iree-runtime/artifacts -IREE_CMAKE_BUILD_DIR=iree-runtime/${IREE_BUILD_TARGET}/iree-build -IREE_RUNTIME_BUILD_DIR=iree-runtime/${IREE_BUILD_TARGET}/build -IREE_INSTALL_DIR=iree-runtime/${IREE_BUILD_TARGET}/install HOST_ARCH=$(uname -s)-$(uname -m) -echo "Building for target: ${IREE_BUILD_TARGET}" -make ${NUM_JOBS} compile IREE_GIT_REV=$(mix iree.version) IREE_INSTALL_DIR=${IREE_INSTALL_DIR} IREE_CMAKE_BUILD_DIR=${IREE_CMAKE_BUILD_DIR} IREE_RUNTIME_BUILD_DIR=${IREE_RUNTIME_BUILD_DIR} IREE_BUILD_TARGET=${IREE_BUILD_TARGET} +build() { + local IREE_CMAKE_BUILD_DIR=iree-runtime/$1/iree-build + local IREE_RUNTIME_BUILD_DIR=iree-runtime/$1/build + local IREE_INSTALL_DIR=iree-runtime/$1/install + + if $2; then + export IREE_HOST_INSTALL_DIR=iree-runtime/host/install + fi + + echo "Building for target: $1" + echo "IREE_HOST_INSTALL_DIR: ${IREE_HOST_INSTALL_DIR}" + make ${NUM_JOBS} compile \ + IREE_GIT_REV=$(mix iree.version) \ + IREE_INSTALL_DIR=${IREE_INSTALL_DIR} \ + IREE_CMAKE_BUILD_DIR=${IREE_CMAKE_BUILD_DIR} \ + IREE_RUNTIME_BUILD_DIR=${IREE_RUNTIME_BUILD_DIR} \ + IREE_BUILD_TARGET=$1 +} + +if $build_host_flag; then + echo "Building Host Runtime" + build host true +fi + +build $IREE_BUILD_TARGET false TAR_NAME=iree-runtime/artifacts/nx_iree-${HOST_ARCH}-${IREE_BUILD_TARGET}.tar.gz