Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rust bindings build on windows #1584

Merged
merged 11 commits into from
Apr 16, 2022
16 changes: 7 additions & 9 deletions .github/workflows/Crate-publishing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ jobs:
fail-fast: false
matrix:
config:
- {
- {
os: windows-2019,
arch: x64,
name: 'Windows x86_64'
}
- {
- {
os: windows-2019,
arch: x86,
name: 'Windows x86'
}
- {
- {
os: ubuntu-latest,
arch: x64,
name: 'Ubuntu x86_64'
}
- {
- {
os: macos-latest,
arch: x64,
name: 'macOS x86_64'
Expand Down Expand Up @@ -69,15 +69,13 @@ jobs:

- name: '🚧 Cargo test'
if: "!startsWith(github.ref, 'refs/tags')"
env:
UNICORN_LOCAL: uc
run: |
cd bindings/rust && cargo test
cargo test

- name: '📦 Cargo Publish'
if: startsWith(github.ref, 'refs/tags') && contains(matrix.config.os, 'ubuntu')
env:
TOKEN: ${{ secrets.cratesio_token }}
UNICORN_VERSION: dev
run: |
cd bindings/rust && cargo login $TOKEN && cargo test && cargo publish
cargo login $TOKEN && cargo test && cargo publish
22 changes: 3 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,7 @@
*.jar
*~

qemu/aarch64-softmmu/
qemu/aarch64eb-softmmu/
qemu/arm-softmmu/
qemu/armeb-softmmu/
qemu/m68k-softmmu/
qemu/mips64el-softmmu/
qemu/mips64-softmmu/
qemu/mipsel-softmmu/
qemu/mips-softmmu/
qemu/sparc64-softmmu/
qemu/sparc-softmmu/
qemu/i386-softmmu/
qemu/x86_64-softmmu/
qemu/ppc-softmmu/
qemu/ppc64-softmmu/
qemu/riscv32-softmmu/
qemu/riscv64-softmmu/
qemu/*-softmmu/

tags
qemu/config-host.ld
Expand Down Expand Up @@ -68,8 +52,8 @@ bindings/python/unicorn.egg-info/
bindings/python/unicorn/lib/
bindings/python/unicorn/include/
bindings/python/MANIFEST
bindings/rust/target/
bindings/rust/Cargo.lock
target/
Cargo.lock
config.log


Expand Down
54 changes: 39 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

cmake_minimum_required(VERSION 3.1)

if(MSVC)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
# set all policies to max supported by actual running cmake version
# mainly want the following:
# CMP0091: prevent msvcrt flags being added to default CMAKE_<LANG>_FLAGS_<CONFIG>
# CMP0092: prevent warning flags being added to default CMAKE_<LANG>_FLAGS
cmake_policy(VERSION ${CMAKE_VERSION})
else()
message(FATAL_ERROR "please update cmake")
endif()
endif()

# Workaround to fix wrong compiler on macos.
if(APPLE AND NOT CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER "/usr/bin/cc")
Expand All @@ -12,13 +24,16 @@ endif()
set(PROJECT_IS_TOP_LEVEL OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(PROJECT_IS_TOP_LEVEL ON)

# Enable folder support
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()

project(unicorn C)

# mainline qemu mostly just uses compiler default
set(CMAKE_C_STANDARD 11)

set(UNICORN_VERSION_MAJOR 2)
set(UNICORN_VERSION_MINOR 0)
set(UNICORN_VERSION_PATCH 0)
Expand Down Expand Up @@ -63,6 +78,7 @@ if(MSVC)
else()
message(FATAL_ERROR "Neither WIN64 or WIN32!")
endif()

add_compile_options(
-Dinline=__inline
-D__func__=__FUNCTION__
Expand All @@ -71,22 +87,30 @@ if(MSVC)
${MSVC_FLAG}
/I${CMAKE_CURRENT_SOURCE_DIR}/qemu/tcg/i386
)

# Disable some warnings
add_compile_options(
/wd4018
/wd4098
/wd4244
/wd4267
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(REPLACE "/ZI" "/Zi" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4018>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4098>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4244>)
add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4267>)

# handle msvcrt setting being passed in CMAKE_C_FLAGS
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
# do not support other methods of setting this (it would be more conformant, tho)
message(FATAL_ERROR "please set msvcrt via CMAKE_C_FLAGS")
endif()
# default use the multithread, static version of the run-time library.
option(UNICORN_STATIC_MSVCRT "Embed static runtime library" ${PROJECT_IS_TOP_LEVEL})
if(UNICORN_STATIC_MSVCRT)
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
if(CMAKE_C_FLAGS MATCHES "[/-]MTd")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MDd")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MT")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MD")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()

# prevent the arg from occurring more than once (not a big deal, just to keep tidy)
string(REGEX REPLACE "[/-]M[TD]d?" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
else()
if(MINGW)
execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpmachine
Expand Down Expand Up @@ -1181,7 +1205,7 @@ if(UNICORN_TRACER)
target_compile_options(unicorn PRIVATE -DUNICORN_TRACER)
endif()

target_compile_options(unicorn-common PRIVATE
target_compile_options(unicorn-common PRIVATE
${UNICORN_COMPILE_OPTIONS}
)

Expand Down
44 changes: 44 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
wtdcode marked this conversation as resolved.
Show resolved Hide resolved
name = "unicorn-engine"
version = "2.0.0-rc6"
authors = ["Ziqiao Kong", "Lukas Seidel"]
documentation = "https://github.com/unicorn-engine/unicorn/wiki"
edition = "2021"
license = "GPL-2.0"
readme = "README.md"
repository = "https://github.com/unicorn-engine/unicorn"
description = "Rust bindings for the Unicorn emulator with utility functions"
build = "bindings/rust/build.rs"
links = "unicorn"
# use `cargo publish --list` to see files to be included
# the resulting list what cargo uses to check for out-of-date files during build
exclude = [
"/docs",
"/bindings/dotnet",
"/bindings/go",
"/bindings/haskell",
"/bindings/java",
"/bindings/pascal",
"/bindings/python",
"/bindings/ruby",
"/bindings/vb6",
"/samples",
"/tests",
]

[lib]
path = "bindings/rust/src/lib.rs"

[dependencies]
bitflags = "1.3"
libc = "0.2"

[build-dependencies]
cc = { optional = true, version = "1.0" }
cmake = { optional = true, version = "0.1" }
pkg-config = { optional = true, version = "0.3" }

[features]
default = ["build_unicorn_cmake"]
build_unicorn_cmake = ["cc", "cmake"]
use_system_unicorn = ["pkg-config"]
37 changes: 0 additions & 37 deletions bindings/rust/Cargo.toml

This file was deleted.

Loading