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
49 changes: 34 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CMake setup for Unicorn 2.
# By Huitao Chen & Nguyen Anh Quynh, 2019-2020

cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
shuffle2 marked this conversation as resolved.
Show resolved Hide resolved

# Workaround to fix wrong compiler on macos.
if(APPLE AND NOT CMAKE_C_COMPILER)
Expand All @@ -12,13 +12,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 All @@ -32,6 +35,12 @@ 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")
option(UNICORN_TRACER "Trace unicorn execution" OFF)

if(DEFINED ENV{CARGO})
shuffle2 marked this conversation as resolved.
Show resolved Hide resolved
set(CARGO TRUE)
set(BUILD_SHARED_LIBS OFF)
set(UNICORN_BUILD_TESTS OFF)
endif()

foreach(ARCH_LOOP ${UNICORN_ARCH})
string(TOUPPER "${ARCH_LOOP}" ARCH_LOOP)
set(UNICORN_HAS_${ARCH_LOOP} TRUE)
Expand Down Expand Up @@ -63,6 +72,7 @@ if(MSVC)
else()
message(FATAL_ERROR "Neither WIN64 or WIN32!")
endif()

add_compile_options(
-Dinline=__inline
-D__func__=__FUNCTION__
Expand All @@ -71,21 +81,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})
endif()
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>)

# 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(CARGO)
# rust always links against the non-debug MT or MD
if(CMAKE_C_FLAGS MATCHES "[/-]MT")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
elseif(CMAKE_C_FLAGS MATCHES "[/-]MD")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
else()
message(FATAL_ERROR "didn't find expected msvcrt type")
endif()

# prevent the arg from occurring more than once (not a big deal, just to keep tidy)
string(REGEX REPLACE "[/-]M[TD]" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
elseif(UNICORN_STATIC_MSVCRT)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
else()
if(MINGW)
Expand Down Expand Up @@ -1181,7 +1200,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