Repository: alibaba/GraphScope (language: python)

Issue:
[BUG] Fail to run interactive: illegal instructions
System info
```text
Linux ip-172-31-37-103 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
```

It is so strage
<img width="1440" alt="截屏2024-07-16 14 40 59" src="https://github.com/user-attachments/assets/06e887d8-57ac-465b-9eb5-3bf28bc6d9f2">



Discussion / hints:
Similar problem when running Interactive image on MacOS(M2);

![截屏2024-08-14 14 59 23](https://github.com/user-attachments/assets/c0c57258-188a-4845-b37d-ecc5adace05d)


![截屏2024-08-14 14 48 58](https://github.com/user-attachments/assets/9e20a36f-45f1-4ca6-b9c0-77c708d57688)

**details**
- The image was built on linux arm64 machine, and it seems to work fine on a linux arm64 machine `Linux 5.10.134-16.3.al8.aarch64 #1 SMP Tue Mar 26 18:51:35 CST 2024 aarch64 aarch64 aarch64 GNU/Linux`
- However, its failed to run on my MacOS laptop: `Darwin 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020 arm64`


Fix patch:
diff --git a/flex/CMakeLists.txt b/flex/CMakeLists.txt
index dd906d667f71..98c96b4cf651 100644
--- a/flex/CMakeLists.txt
+++ b/flex/CMakeLists.txt
@@ -14,6 +14,7 @@ option(BUILD_TEST "Whether to build test" ON)
 option(BUILD_DOC "Whether to build doc" OFF)
 option(BUILD_ODPS_FRAGMENT_LOADER "Whether to build odps fragment loader" OFF)
 option(USE_PTHASH "Whether to use pthash" OFF)
+option(OPTIMIZE_FOR_HOST "Whether to optimize on host" ON) # Whether to build optimized code on host
 
 #print options
 message(STATUS "Build test: ${BUILD_TEST}")
@@ -76,7 +77,10 @@ else ()
     endif ()
 endif ()
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Werror -std=c++17 -Wall -fPIC -march=native")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Werror -std=c++17 -Wall -fPIC")
+if (OPTIMIZE_FOR_HOST)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
+endif()
 
 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g")
diff --git a/k8s/Makefile b/k8s/Makefile
index 4dfb2e9fdb47..6cd8ac4b3c16 100644
--- a/k8s/Makefile
+++ b/k8s/Makefile
@@ -21,6 +21,8 @@ PROFILE ?= release
 CI ?= false
 # Flex Coordinator
 ENABLE_COORDINATOR ?= false
+# Flex Interactive: controls whether optimize for host, should be enabled when building images
+OPTIMIZE_FOR_HOST:= OFF
 
 BUILD_PROGRESS  	?= auto
 
@@ -167,6 +169,7 @@ flex-interactive:
 		--build-arg BUILDER_VERSION=$(BUILDER_VERSION) \
 		--build-arg PLATFORM=${PLATFORM} \
 		--build-arg ARCH=${ARCH} \
+		--build-arg OPTIMIZE_FOR_HOST=${OPTIMIZE_FOR_HOST} \
 		-t graphscope/interactive:${VERSION}  \
 		-f ${DOCKERFILES_DIR}/flex-interactive.Dockerfile .
 
diff --git a/k8s/dockerfiles/flex-interactive.Dockerfile b/k8s/dockerfiles/flex-interactive.Dockerfile
index ed852bdc4f5b..556488bc59c3 100644
--- a/k8s/dockerfiles/flex-interactive.Dockerfile
+++ b/k8s/dockerfiles/flex-interactive.Dockerfile
@@ -6,6 +6,7 @@ ARG REGISTRY=registry.cn-hongkong.aliyuncs.com
 ARG BUILDER_VERSION=latest
 FROM $REGISTRY/graphscope/graphscope-dev:$BUILDER_VERSION-$ARCH AS builder
 ARG ENABLE_COORDINATOR="false"
+ARG OPTIMIZE_FOR_HOST=OFF
 
 RUN sudo mkdir -p /opt/flex && sudo chown -R graphscope:graphscope /opt/flex/
 USER graphscope
@@ -39,7 +40,7 @@ COPY --chown=graphscope:graphscope . /home/graphscope/GraphScope
 
 # install flex
 RUN . ${HOME}/.cargo/env  && cd ${HOME}/GraphScope/flex && \
-    git submodule update --init && mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/opt/flex -DBUILD_DOC=OFF -DBUILD_TEST=OFF && make -j && make install && \
+    git submodule update --init && mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=/opt/flex -DBUILD_DOC=OFF -DBUILD_TEST=OFF -DOPTIMIZE_FOR_HOST=${OPTIMIZE_FOR_HOST} && make -j && make install && \
     cd ~/GraphScope/interactive_engine/ && mvn clean package -Pexperimental -DskipTests && \
     cd ~/GraphScope/interactive_engine/compiler && cp target/compiler-0.0.1-SNAPSHOT.jar /opt/flex/lib/ && \
     cp target/libs/*.jar /opt/flex/lib/ && \


Test patch:
diff --git a/docs/flex/interactive/development/dev_and_test.md b/docs/flex/interactive/development/dev_and_test.md
index f7fa915a444e..9b272a2f403c 100644
--- a/docs/flex/interactive/development/dev_and_test.md
+++ b/docs/flex/interactive/development/dev_and_test.md
@@ -83,6 +83,14 @@ cd interactive_engine
 mvn clean package -DskipTests -Pexperimental
 ```
 
+### CMake options
+
+- `BUILD_TEST`: Indicates whether to build tests.  
+- `BUILD_DOC`: Indicates whether to build Flex documentation.  
+- `BUILD_ODPS_FRAGMENT_LOADER`: Enables support for loading graphs from ODPS tables.  
+- `USE_PTHASH`: Indicates whether to use a perfect hash when building the vertex map.  
+- `OPTIMIZE_FOR_HOST`: Determines if Flex should be optimized for performance on the current machine. Note that enabling this option may result in a binary that does not run on different platforms or CPU architectures.
+
 ## Testing
 
 Numerous test cases have been created for Interactive, which can be referenced in the GitHub workflow[interactive.yaml](https://github.com/alibaba/GraphScope/blob/main/.github/workflows/interactive.yml).