Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Jul 7, 2022
2 parents 5552085 + 1ec1352 commit 6c1cbef
Show file tree
Hide file tree
Showing 85 changed files with 19,603 additions and 423 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/PyPI-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ jobs:
uses: microsoft/[email protected]
with:
vs-version: '16.5'

- name: '🛠️ Win MSVC 32 dev cmd setup'
if: contains(matrix.config.name, 'win32')
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86

- name: '🛠️ Win MSVC 64 dev cmd setup'
if: contains(matrix.config.name, 'win_amd64')
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: '🛠️ Win build dependencies'
if: contains(matrix.config.name, 'win')
Expand Down
51 changes: 45 additions & 6 deletions .github/workflows/build-uc2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,22 @@ jobs:
arch: x64,
python-arch: x64,
python-ver: '3.8',
name: 'windows-x64 MINGW64',
name: 'windows-x64 MINGW64 shared',
shared: 'yes',
mingw: MINGW64,
mingw-arch: x86_64,
artifact: 'windows_mingw64.7z',
build_type: 'Debug',
archiver: '7z a',
generators: 'Ninja'
}
- {
os: windows-2019,
arch: x64,
python-arch: x64,
python-ver: '3.8',
name: 'windows-x64 MINGW64 static',
shared: 'no',
mingw: MINGW64,
mingw-arch: x86_64,
artifact: 'windows_mingw64.7z',
Expand All @@ -44,7 +59,22 @@ jobs:
arch: x64,
python-arch: x64,
python-ver: '3.8',
name: 'windows-x64 MINGW32',
name: 'windows-x64 MINGW32 shared',
shared: "yes",
mingw: MINGW32,
mingw-arch: i686,
artifact: 'windows_mingw32.7z',
build_type: 'Debug',
archiver: '7z a',
generators: 'Ninja'
}
- {
os: windows-2019,
arch: x64,
python-arch: x64,
python-ver: '3.8',
name: 'windows-x64 MINGW32 static',
shared: "no",
mingw: MINGW32,
mingw-arch: i686,
artifact: 'windows_mingw32.7z',
Expand Down Expand Up @@ -124,6 +154,12 @@ jobs:
- name: '🛠️ Win MSVC 64 setup'
if: contains(matrix.config.name, 'MSVC 64')
uses: microsoft/setup-msbuild@v1

- name: '🛠️ Win MSVC 64 dev cmd setup'
if: contains(matrix.config.name, 'MSVC 64')
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: '🚧 Win MSVC 64 build'
if: contains(matrix.config.name, 'MSVC 64')
Expand All @@ -138,7 +174,8 @@ jobs:
-B . \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-G "${{ matrix.config.generators }}" \
-DCMAKE_INSTALL_PREFIX:PATH=instdir
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
cmake --build . --config ${{ matrix.config.build_type }}
cmake --install . --strip --config ${{ matrix.config.build_type }}
ctest -VV -C ${{ matrix.config.build_type }}
Expand All @@ -164,7 +201,8 @@ jobs:
-A "win32" \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-G "${{ matrix.config.generators }}" \
-DCMAKE_INSTALL_PREFIX:PATH=instdir
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
cmake --build . --config ${{ matrix.config.build_type }}
cmake --install . --strip --config ${{ matrix.config.build_type }}
ctest -VV -C ${{ matrix.config.build_type }}
Expand All @@ -191,7 +229,8 @@ jobs:
-B . \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-G "${{ matrix.config.generators }}" \
-DCMAKE_INSTALL_PREFIX:PATH=instdir
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
cmake --build . --config ${{ matrix.config.build_type }}
cmake --install . --strip
ctest -VV -C ${{ matrix.config.build_type }}
Expand Down Expand Up @@ -277,7 +316,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-G "${{ matrix.config.generators }}" \
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
-DBUILD_SHARED_LIB= ${{ matrix.config.shared }}
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
cmake --build . --config ${{ matrix.config.build_type }}
cmake --install . --strip
ctest -VV -C ${{ matrix.config.build_type }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.dll
*.class
*.jar
*.gem
*~

qemu/*-softmmu/
Expand Down Expand Up @@ -52,7 +53,7 @@ bindings/python/unicorn.egg-info/
bindings/python/unicorn/lib/
bindings/python/unicorn/include/
bindings/python/MANIFEST
target/
/target/
Cargo.lock
config.log

Expand Down
135 changes: 116 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ set(UNICORN_VERSION_PATCH 0)

include(bundle_static.cmake)

# Even though we generate shared lib and static archive at the same time, we still support
# using unicorn as a subdirectory so we have to respect BUILD_SHARED_LIBS.
#
# Also we would like users to link a native cmake target, instead of a custom target for better
# compatability.
option(BUILD_SHARED_LIBS "Build shared instead of static library" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_FUZZ "Enable fuzzing" OFF)
option(UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_INSTALL "Enable unicorn installation" ${PROJECT_IS_TOP_LEVEL})
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x" CACHE STRING "Enabled unicorn architectures")
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x;tricore" CACHE STRING "Enabled unicorn architectures")
option(UNICORN_TRACER "Trace unicorn execution" OFF)

foreach(ARCH_LOOP ${UNICORN_ARCH})
Expand Down Expand Up @@ -119,7 +124,7 @@ else()
string(FIND "${UC_COMPILER_VERSION}" "i686" UC_RET)
if(${UC_RET} GREATER_EQUAL "0")
set(UNICORN_TARGET_ARCH "i386")
set(UNICORN_CFLAGS -m32)
set(UNICORN_CFLAGS -m32 -static-libgcc) # Workaround for github action bugs
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
else()
Expand Down Expand Up @@ -209,6 +214,11 @@ else()
set(UNICORN_TARGET_ARCH "s390")
break()
endif()
string(FIND ${UC_COMPILER_MACRO} "__tricore__" UC_RET)
if (${UC_RET} GREATER_EQUAL "0")
set(UNICORN_TARGET_ARCH "tricore")
break()
endif()
message(FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER}.")
endwhile(TRUE)
endif()
Expand Down Expand Up @@ -241,6 +251,9 @@ else()
if (UNICORN_HAS_S390X)
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_S390X ")
endif()
if (UNICORN_HAS_TRICORE)
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_TRICORE ")
endif()

set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-fPIC")
if(ANDROID_ABI)
Expand Down Expand Up @@ -282,6 +295,9 @@ else()
if(UNICORN_HAS_S390X)
set(TARGET_LIST "${TARGET_LIST}s390x-softmmu, ")
endif()
if (UNICORN_HAS_TRICORE)
set (TARGET_LIST "${TARGET_LIST}tricore-softmmu, ")
endif()
set(TARGET_LIST "${TARGET_LIST} ")

# GEN config-host.mak & target directories
Expand Down Expand Up @@ -373,6 +389,12 @@ else()
OUTPUT_FILE ${CMAKE_BINARY_DIR}/s390x-softmmu/config-target.h
)
endif()
if (UNICORN_HAS_TRICORE)
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
INPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.mak
OUTPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.h
)
endif()
add_compile_options(
${UNICORN_CFLAGS}
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/${UNICORN_TARGET_ARCH}
Expand Down Expand Up @@ -1034,6 +1056,36 @@ endif()
endif()


if (UNICORN_HAS_TRICORE)
add_library(tricore-softmmu STATIC
${UNICORN_ARCH_COMMON}

qemu/target/tricore/cpu.c
qemu/target/tricore/fpu_helper.c
qemu/target/tricore/helper.c
qemu/target/tricore/op_helper.c
qemu/target/tricore/translate.c
qemu/target/tricore/unicorn.c
)

if(MSVC)
target_compile_options(tricore-softmmu PRIVATE
-DNEED_CPU_H
/FItricore.h
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/tricore-softmmu
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/tricore
)
else()
target_compile_options(tricore-softmmu PRIVATE
-DNEED_CPU_H
-include tricore.h
-I${CMAKE_BINARY_DIR}/tricore-softmmu
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/tricore
)
endif()
endif()


set(UNICORN_SRCS
uc.c

Expand Down Expand Up @@ -1093,6 +1145,7 @@ if(MSVC)
enable_language(ASM_MASM)
endif()
set(UNICORN_COMMON_SRCS ${UNICORN_COMMON_SRCS} qemu/util/setjmp-wrapper-win32.asm)
set_property(SOURCE qemu/util/setjmp-wrapper-win32.asm PROPERTY LANGUAGE ASM_MASM)
endif()
else()
set(UNICORN_COMMON_SRCS
Expand All @@ -1110,14 +1163,12 @@ if(NOT MSVC AND NOT ANDROID_ABI)
target_link_libraries(unicorn-common PRIVATE pthread)
endif()

add_library(unicorn ${UNICORN_SRCS})
# For static archive
if (BUILD_SHARED_LIBS)
set(UNICORN_LIB_NAME "unicorn")
else()
set(UNICORN_LIB_NAME "unicorn-static") # This static lib is useless and it's just an intermediate target
add_library(unicorn_static STATIC ${UNICORN_SRCS})
endif()

add_library(${UNICORN_LIB_NAME} ${UNICORN_SRCS})

if(BUILD_SHARED_LIBS)
if(ANDROID_ABI)
file(APPEND ${CMAKE_BINARY_DIR}/adb.sh "adb push ./libunicorn.so /data/local/tmp/build/\n")
Expand Down Expand Up @@ -1194,6 +1245,13 @@ if (UNICORN_HAS_S390X)
target_link_libraries(s390x-softmmu PRIVATE unicorn-common)
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_s390x)
endif()
if (UNICORN_HAS_TRICORE)
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_TRICORE)
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} tricore-softmmu)
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_tricore)
target_link_libraries(tricore-softmmu unicorn-common)
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_tricore)
endif()

# Extra tests
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)
Expand All @@ -1209,10 +1267,17 @@ target_compile_options(unicorn-common PRIVATE
${UNICORN_COMPILE_OPTIONS}
)

target_compile_options(${UNICORN_LIB_NAME} PRIVATE
target_compile_options(unicorn PRIVATE
${UNICORN_COMPILE_OPTIONS}
)

# For static archive
if (BUILD_SHARED_LIBS)
target_compile_options(unicorn_static PRIVATE
${UNICORN_COMPILE_OPTIONS}
)
endif()

if(MINGW)
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} pthread)
endif()
Expand All @@ -1223,29 +1288,46 @@ endif()

if(MSVC)
if(BUILD_SHARED_LIBS)
target_compile_options(${UNICORN_LIB_NAME} PRIVATE
target_compile_options(unicorn PRIVATE
-DUNICORN_SHARED
)

# For static archive
target_link_libraries(unicorn_static PRIVATE
${UNICORN_LINK_LIBRARIES}
)
endif()

target_link_libraries(${UNICORN_LIB_NAME} PRIVATE
target_link_libraries(unicorn PRIVATE
${UNICORN_LINK_LIBRARIES}
)

set_target_properties(${UNICORN_LIB_NAME} PROPERTIES
set_target_properties(unicorn PROPERTIES
VERSION "${UNICORN_VERSION_MAJOR}.${UNICORN_VERSION_MINOR}"
)
else()
target_link_libraries(${UNICORN_LIB_NAME} PRIVATE
target_link_libraries(unicorn PRIVATE
${UNICORN_LINK_LIBRARIES}
m
)

target_link_libraries(${UNICORN_LIB_NAME} PUBLIC
target_link_libraries(unicorn PUBLIC
m
)

set_target_properties(${UNICORN_LIB_NAME} PROPERTIES
# For static archive
if (BUILD_SHARED_LIBS)
target_link_libraries(unicorn_static PUBLIC
m
)

target_link_libraries(unicorn_static PRIVATE
${UNICORN_LINK_LIBRARIES}
m
)
endif()

set_target_properties(unicorn PROPERTIES
VERSION ${UNICORN_VERSION_MAJOR}
SOVERSION ${UNICORN_VERSION_MAJOR}
)
Expand All @@ -1266,12 +1348,28 @@ else()
)
endif()

target_include_directories(${UNICORN_LIB_NAME} PUBLIC
target_include_directories(unicorn PUBLIC
include
)

if (NOT BUILD_SHARED_LIBS)
bundle_static_library(${UNICORN_LIB_NAME} unicorn) # Bundle our real unicorn static lib
# For static archive
if (BUILD_SHARED_LIBS)
target_include_directories(unicorn_static PUBLIC
include
)
endif()

# Black magic for generating static archives...
if (BUILD_SHARED_LIBS)
if (MSVC)
# Avoid the import lib built by MVSC clash with our archive.
set_target_properties(unicorn PROPERTIES ARCHIVE_OUTPUT_NAME "unicorn-import")
endif()
bundle_static_library(unicorn_static unicorn_archive unicorn)
else()
# Rename the "static" lib to avoid filename clash.
set_target_properties(unicorn PROPERTIES OUTPUT_NAME "unicorn-static")
bundle_static_library(unicorn unicorn_archive unicorn)
endif()

if(UNICORN_FUZZ)
Expand Down Expand Up @@ -1327,9 +1425,8 @@ if(UNICORN_INSTALL AND NOT MSVC)
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
else()
install(FILES $<TARGET_FILE:unicorn> DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES $<TARGET_FILE:unicorn_archive> DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unicorn)
file(WRITE ${CMAKE_BINARY_DIR}/unicorn.pc "Name: unicorn\n\
Description: Unicorn emulator engine\n\
Expand Down
Loading

0 comments on commit 6c1cbef

Please sign in to comment.