Skip to content

Commit

Permalink
Patch mcl for arm build (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinxc authored Oct 21, 2023
1 parent ebf4530 commit f933d7f
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions bazel/patches/mcl.patch
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b54b261..4c8eb32b 100644
index 2b54b261..5c1f14c7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -146,6 +146,11 @@ target_compile_options(mcl_st PRIVATE ${MCL_COMPILE_OPTIONS})
@@ -145,6 +145,10 @@ target_compile_options(mcl_st PRIVATE ${MCL_COMPILE_OPTIONS})
# target_compile_features(mcl PUBLIC cxx_std_11)
# target_compile_features(mcl_st PUBLIC cxx_std_11)


+set(TARGET_FLAG "")
+if(DEFINED CMAKE_ANDROID_ARCH_LLVM_TRIPLE)
+ set(TARGET_FLAG "--target=${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}")
+endif()
+
# use bint-x64 on x64, bint${BIT}.ll on the other CPU
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
find_program(ML64 ml64.exe HINTS "${cl_path}" DOC "path to assembler")
@@ -172,7 +177,7 @@ else()
@@ -163,16 +167,16 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
target_sources(mcl PRIVATE src/asm/bint-x64-amd64.S)
target_sources(mcl_st PRIVATE src/asm/bint-x64-amd64.S)
else()
- if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ..")
- endif()
+ # if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ # message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ..")
+ # endif()
set(BINT_OBJ "${CMAKE_CURRENT_BINARY_DIR}/bint${BIT}.o")
message("bint_obj=" ${BINT_OBJ})
target_compile_definitions(mcl PUBLIC MCL_BINT_ASM_X64=0)
target_compile_definitions(mcl_st PUBLIC MCL_BINT_ASM_X64=0)

add_custom_command(OUTPUT ${BINT_OBJ}
- COMMAND ${CMAKE_CXX_COMPILER} -c -o ${BINT_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/bint${BIT}.ll -O3 -fPIC
+ COMMAND ${CMAKE_CXX_COMPILER} -c -o ${BINT_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/bint${BIT}.ll -O3 -fPIC ${TARGET_FLAG}
+ COMMAND clang++ -c -o ${BINT_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/bint${BIT}.ll -O3 -fPIC ${TARGET_FLAG}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(gen_bint.o
SOURCES ${BINT_OBJ})
@@ -199,7 +204,7 @@ elseif(${MCL_USE_LLVM})
@@ -199,7 +203,7 @@ elseif(${MCL_USE_LLVM})
target_compile_definitions(mcl_st PUBLIC MCL_USE_LLVM=1)

add_custom_command(OUTPUT ${BASE_OBJ}
- COMMAND ${CMAKE_CXX_COMPILER} -c -o ${BASE_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/base${BIT}.ll -O3 -fPIC
+ COMMAND ${CMAKE_CXX_COMPILER} -c -o ${BASE_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/base${BIT}.ll -O3 -fPIC ${TARGET_FLAG}
+ COMMAND clang++ -c -o ${BASE_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/base${BIT}.ll -O3 -fPIC ${TARGET_FLAG}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(gen_base.o
SOURCES ${BASE_OBJ})

0 comments on commit f933d7f

Please sign in to comment.