Skip to content

Commit 6c1cbef

Browse files
committed
Merge branch 'dev'
2 parents 5552085 + 1ec1352 commit 6c1cbef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+19603
-423
lines changed

.github/workflows/PyPI-publishing.yml

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ jobs:
7171
uses: microsoft/[email protected]
7272
with:
7373
vs-version: '16.5'
74+
75+
- name: '🛠️ Win MSVC 32 dev cmd setup'
76+
if: contains(matrix.config.name, 'win32')
77+
uses: ilammy/msvc-dev-cmd@v1
78+
with:
79+
arch: x86
80+
81+
- name: '🛠️ Win MSVC 64 dev cmd setup'
82+
if: contains(matrix.config.name, 'win_amd64')
83+
uses: ilammy/msvc-dev-cmd@v1
84+
with:
85+
arch: x64
7486

7587
- name: '🛠️ Win build dependencies'
7688
if: contains(matrix.config.name, 'win')

.github/workflows/build-uc2.yml

+45-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,22 @@ jobs:
3131
arch: x64,
3232
python-arch: x64,
3333
python-ver: '3.8',
34-
name: 'windows-x64 MINGW64',
34+
name: 'windows-x64 MINGW64 shared',
35+
shared: 'yes',
36+
mingw: MINGW64,
37+
mingw-arch: x86_64,
38+
artifact: 'windows_mingw64.7z',
39+
build_type: 'Debug',
40+
archiver: '7z a',
41+
generators: 'Ninja'
42+
}
43+
- {
44+
os: windows-2019,
45+
arch: x64,
46+
python-arch: x64,
47+
python-ver: '3.8',
48+
name: 'windows-x64 MINGW64 static',
49+
shared: 'no',
3550
mingw: MINGW64,
3651
mingw-arch: x86_64,
3752
artifact: 'windows_mingw64.7z',
@@ -44,7 +59,22 @@ jobs:
4459
arch: x64,
4560
python-arch: x64,
4661
python-ver: '3.8',
47-
name: 'windows-x64 MINGW32',
62+
name: 'windows-x64 MINGW32 shared',
63+
shared: "yes",
64+
mingw: MINGW32,
65+
mingw-arch: i686,
66+
artifact: 'windows_mingw32.7z',
67+
build_type: 'Debug',
68+
archiver: '7z a',
69+
generators: 'Ninja'
70+
}
71+
- {
72+
os: windows-2019,
73+
arch: x64,
74+
python-arch: x64,
75+
python-ver: '3.8',
76+
name: 'windows-x64 MINGW32 static',
77+
shared: "no",
4878
mingw: MINGW32,
4979
mingw-arch: i686,
5080
artifact: 'windows_mingw32.7z',
@@ -124,6 +154,12 @@ jobs:
124154
- name: '🛠️ Win MSVC 64 setup'
125155
if: contains(matrix.config.name, 'MSVC 64')
126156
uses: microsoft/setup-msbuild@v1
157+
158+
- name: '🛠️ Win MSVC 64 dev cmd setup'
159+
if: contains(matrix.config.name, 'MSVC 64')
160+
uses: ilammy/msvc-dev-cmd@v1
161+
with:
162+
arch: x64
127163

128164
- name: '🚧 Win MSVC 64 build'
129165
if: contains(matrix.config.name, 'MSVC 64')
@@ -138,7 +174,8 @@ jobs:
138174
-B . \
139175
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
140176
-G "${{ matrix.config.generators }}" \
141-
-DCMAKE_INSTALL_PREFIX:PATH=instdir
177+
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
178+
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
142179
cmake --build . --config ${{ matrix.config.build_type }}
143180
cmake --install . --strip --config ${{ matrix.config.build_type }}
144181
ctest -VV -C ${{ matrix.config.build_type }}
@@ -164,7 +201,8 @@ jobs:
164201
-A "win32" \
165202
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
166203
-G "${{ matrix.config.generators }}" \
167-
-DCMAKE_INSTALL_PREFIX:PATH=instdir
204+
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
205+
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
168206
cmake --build . --config ${{ matrix.config.build_type }}
169207
cmake --install . --strip --config ${{ matrix.config.build_type }}
170208
ctest -VV -C ${{ matrix.config.build_type }}
@@ -191,7 +229,8 @@ jobs:
191229
-B . \
192230
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
193231
-G "${{ matrix.config.generators }}" \
194-
-DCMAKE_INSTALL_PREFIX:PATH=instdir
232+
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
233+
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
195234
cmake --build . --config ${{ matrix.config.build_type }}
196235
cmake --install . --strip
197236
ctest -VV -C ${{ matrix.config.build_type }}
@@ -277,7 +316,7 @@ jobs:
277316
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
278317
-G "${{ matrix.config.generators }}" \
279318
-DCMAKE_INSTALL_PREFIX:PATH=instdir \
280-
-DBUILD_SHARED_LIB= ${{ matrix.config.shared }}
319+
-DBUILD_SHARED_LIBS=${{ matrix.config.shared }}
281320
cmake --build . --config ${{ matrix.config.build_type }}
282321
cmake --install . --strip
283322
ctest -VV -C ${{ matrix.config.build_type }}

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*.dll
1111
*.class
1212
*.jar
13+
*.gem
1314
*~
1415

1516
qemu/*-softmmu/
@@ -52,7 +53,7 @@ bindings/python/unicorn.egg-info/
5253
bindings/python/unicorn/lib/
5354
bindings/python/unicorn/include/
5455
bindings/python/MANIFEST
55-
target/
56+
/target/
5657
Cargo.lock
5758
config.log
5859

CMakeLists.txt

+116-19
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ set(UNICORN_VERSION_PATCH 0)
4040

4141
include(bundle_static.cmake)
4242

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

5055
foreach(ARCH_LOOP ${UNICORN_ARCH})
@@ -119,7 +124,7 @@ else()
119124
string(FIND "${UC_COMPILER_VERSION}" "i686" UC_RET)
120125
if(${UC_RET} GREATER_EQUAL "0")
121126
set(UNICORN_TARGET_ARCH "i386")
122-
set(UNICORN_CFLAGS -m32)
127+
set(UNICORN_CFLAGS -m32 -static-libgcc) # Workaround for github action bugs
123128
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
124129
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
125130
else()
@@ -209,6 +214,11 @@ else()
209214
set(UNICORN_TARGET_ARCH "s390")
210215
break()
211216
endif()
217+
string(FIND ${UC_COMPILER_MACRO} "__tricore__" UC_RET)
218+
if (${UC_RET} GREATER_EQUAL "0")
219+
set(UNICORN_TARGET_ARCH "tricore")
220+
break()
221+
endif()
212222
message(FATAL_ERROR "Unknown host compiler: ${CMAKE_C_COMPILER}.")
213223
endwhile(TRUE)
214224
endif()
@@ -241,6 +251,9 @@ else()
241251
if (UNICORN_HAS_S390X)
242252
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_S390X ")
243253
endif()
254+
if (UNICORN_HAS_TRICORE)
255+
set (EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_TRICORE ")
256+
endif()
244257

245258
set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-fPIC")
246259
if(ANDROID_ABI)
@@ -282,6 +295,9 @@ else()
282295
if(UNICORN_HAS_S390X)
283296
set(TARGET_LIST "${TARGET_LIST}s390x-softmmu, ")
284297
endif()
298+
if (UNICORN_HAS_TRICORE)
299+
set (TARGET_LIST "${TARGET_LIST}tricore-softmmu, ")
300+
endif()
285301
set(TARGET_LIST "${TARGET_LIST} ")
286302

287303
# GEN config-host.mak & target directories
@@ -373,6 +389,12 @@ else()
373389
OUTPUT_FILE ${CMAKE_BINARY_DIR}/s390x-softmmu/config-target.h
374390
)
375391
endif()
392+
if (UNICORN_HAS_TRICORE)
393+
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
394+
INPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.mak
395+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/tricore-softmmu/config-target.h
396+
)
397+
endif()
376398
add_compile_options(
377399
${UNICORN_CFLAGS}
378400
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/${UNICORN_TARGET_ARCH}
@@ -1034,6 +1056,36 @@ endif()
10341056
endif()
10351057

10361058

1059+
if (UNICORN_HAS_TRICORE)
1060+
add_library(tricore-softmmu STATIC
1061+
${UNICORN_ARCH_COMMON}
1062+
1063+
qemu/target/tricore/cpu.c
1064+
qemu/target/tricore/fpu_helper.c
1065+
qemu/target/tricore/helper.c
1066+
qemu/target/tricore/op_helper.c
1067+
qemu/target/tricore/translate.c
1068+
qemu/target/tricore/unicorn.c
1069+
)
1070+
1071+
if(MSVC)
1072+
target_compile_options(tricore-softmmu PRIVATE
1073+
-DNEED_CPU_H
1074+
/FItricore.h
1075+
/I${CMAKE_CURRENT_SOURCE_DIR}/msvc/tricore-softmmu
1076+
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/tricore
1077+
)
1078+
else()
1079+
target_compile_options(tricore-softmmu PRIVATE
1080+
-DNEED_CPU_H
1081+
-include tricore.h
1082+
-I${CMAKE_BINARY_DIR}/tricore-softmmu
1083+
-I${CMAKE_CURRENT_SOURCE_DIR}/qemu/target/tricore
1084+
)
1085+
endif()
1086+
endif()
1087+
1088+
10371089
set(UNICORN_SRCS
10381090
uc.c
10391091

@@ -1093,6 +1145,7 @@ if(MSVC)
10931145
enable_language(ASM_MASM)
10941146
endif()
10951147
set(UNICORN_COMMON_SRCS ${UNICORN_COMMON_SRCS} qemu/util/setjmp-wrapper-win32.asm)
1148+
set_property(SOURCE qemu/util/setjmp-wrapper-win32.asm PROPERTY LANGUAGE ASM_MASM)
10961149
endif()
10971150
else()
10981151
set(UNICORN_COMMON_SRCS
@@ -1110,14 +1163,12 @@ if(NOT MSVC AND NOT ANDROID_ABI)
11101163
target_link_libraries(unicorn-common PRIVATE pthread)
11111164
endif()
11121165

1166+
add_library(unicorn ${UNICORN_SRCS})
1167+
# For static archive
11131168
if (BUILD_SHARED_LIBS)
1114-
set(UNICORN_LIB_NAME "unicorn")
1115-
else()
1116-
set(UNICORN_LIB_NAME "unicorn-static") # This static lib is useless and it's just an intermediate target
1169+
add_library(unicorn_static STATIC ${UNICORN_SRCS})
11171170
endif()
11181171

1119-
add_library(${UNICORN_LIB_NAME} ${UNICORN_SRCS})
1120-
11211172
if(BUILD_SHARED_LIBS)
11221173
if(ANDROID_ABI)
11231174
file(APPEND ${CMAKE_BINARY_DIR}/adb.sh "adb push ./libunicorn.so /data/local/tmp/build/\n")
@@ -1194,6 +1245,13 @@ if (UNICORN_HAS_S390X)
11941245
target_link_libraries(s390x-softmmu PRIVATE unicorn-common)
11951246
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_s390x)
11961247
endif()
1248+
if (UNICORN_HAS_TRICORE)
1249+
set(UNICORN_COMPILE_OPTIONS ${UNICORN_COMPILE_OPTIONS} -DUNICORN_HAS_TRICORE)
1250+
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} tricore-softmmu)
1251+
set(UNICORN_SAMPLE_FILE ${UNICORN_SAMPLE_FILE} sample_tricore)
1252+
target_link_libraries(tricore-softmmu unicorn-common)
1253+
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_tricore)
1254+
endif()
11971255

11981256
# Extra tests
11991257
set(UNICORN_TEST_FILE ${UNICORN_TEST_FILE} test_mem)
@@ -1209,10 +1267,17 @@ target_compile_options(unicorn-common PRIVATE
12091267
${UNICORN_COMPILE_OPTIONS}
12101268
)
12111269

1212-
target_compile_options(${UNICORN_LIB_NAME} PRIVATE
1270+
target_compile_options(unicorn PRIVATE
12131271
${UNICORN_COMPILE_OPTIONS}
12141272
)
12151273

1274+
# For static archive
1275+
if (BUILD_SHARED_LIBS)
1276+
target_compile_options(unicorn_static PRIVATE
1277+
${UNICORN_COMPILE_OPTIONS}
1278+
)
1279+
endif()
1280+
12161281
if(MINGW)
12171282
set(UNICORN_LINK_LIBRARIES ${UNICORN_LINK_LIBRARIES} pthread)
12181283
endif()
@@ -1223,29 +1288,46 @@ endif()
12231288

12241289
if(MSVC)
12251290
if(BUILD_SHARED_LIBS)
1226-
target_compile_options(${UNICORN_LIB_NAME} PRIVATE
1291+
target_compile_options(unicorn PRIVATE
12271292
-DUNICORN_SHARED
12281293
)
1294+
1295+
# For static archive
1296+
target_link_libraries(unicorn_static PRIVATE
1297+
${UNICORN_LINK_LIBRARIES}
1298+
)
12291299
endif()
12301300

1231-
target_link_libraries(${UNICORN_LIB_NAME} PRIVATE
1301+
target_link_libraries(unicorn PRIVATE
12321302
${UNICORN_LINK_LIBRARIES}
12331303
)
12341304

1235-
set_target_properties(${UNICORN_LIB_NAME} PROPERTIES
1305+
set_target_properties(unicorn PROPERTIES
12361306
VERSION "${UNICORN_VERSION_MAJOR}.${UNICORN_VERSION_MINOR}"
12371307
)
12381308
else()
1239-
target_link_libraries(${UNICORN_LIB_NAME} PRIVATE
1309+
target_link_libraries(unicorn PRIVATE
12401310
${UNICORN_LINK_LIBRARIES}
12411311
m
12421312
)
12431313

1244-
target_link_libraries(${UNICORN_LIB_NAME} PUBLIC
1314+
target_link_libraries(unicorn PUBLIC
12451315
m
12461316
)
12471317

1248-
set_target_properties(${UNICORN_LIB_NAME} PROPERTIES
1318+
# For static archive
1319+
if (BUILD_SHARED_LIBS)
1320+
target_link_libraries(unicorn_static PUBLIC
1321+
m
1322+
)
1323+
1324+
target_link_libraries(unicorn_static PRIVATE
1325+
${UNICORN_LINK_LIBRARIES}
1326+
m
1327+
)
1328+
endif()
1329+
1330+
set_target_properties(unicorn PROPERTIES
12491331
VERSION ${UNICORN_VERSION_MAJOR}
12501332
SOVERSION ${UNICORN_VERSION_MAJOR}
12511333
)
@@ -1266,12 +1348,28 @@ else()
12661348
)
12671349
endif()
12681350

1269-
target_include_directories(${UNICORN_LIB_NAME} PUBLIC
1351+
target_include_directories(unicorn PUBLIC
12701352
include
12711353
)
12721354

1273-
if (NOT BUILD_SHARED_LIBS)
1274-
bundle_static_library(${UNICORN_LIB_NAME} unicorn) # Bundle our real unicorn static lib
1355+
# For static archive
1356+
if (BUILD_SHARED_LIBS)
1357+
target_include_directories(unicorn_static PUBLIC
1358+
include
1359+
)
1360+
endif()
1361+
1362+
# Black magic for generating static archives...
1363+
if (BUILD_SHARED_LIBS)
1364+
if (MSVC)
1365+
# Avoid the import lib built by MVSC clash with our archive.
1366+
set_target_properties(unicorn PROPERTIES ARCHIVE_OUTPUT_NAME "unicorn-import")
1367+
endif()
1368+
bundle_static_library(unicorn_static unicorn_archive unicorn)
1369+
else()
1370+
# Rename the "static" lib to avoid filename clash.
1371+
set_target_properties(unicorn PROPERTIES OUTPUT_NAME "unicorn-static")
1372+
bundle_static_library(unicorn unicorn_archive unicorn)
12751373
endif()
12761374

12771375
if(UNICORN_FUZZ)
@@ -1327,9 +1425,8 @@ if(UNICORN_INSTALL AND NOT MSVC)
13271425
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
13281426
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
13291427
)
1330-
else()
1331-
install(FILES $<TARGET_FILE:unicorn> DESTINATION ${CMAKE_INSTALL_LIBDIR})
13321428
endif()
1429+
install(FILES $<TARGET_FILE:unicorn_archive> DESTINATION ${CMAKE_INSTALL_LIBDIR})
13331430
install(FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unicorn)
13341431
file(WRITE ${CMAKE_BINARY_DIR}/unicorn.pc "Name: unicorn\n\
13351432
Description: Unicorn emulator engine\n\

0 commit comments

Comments
 (0)