Skip to content

Commit

Permalink
Fix Windows i686 build
Browse files Browse the repository at this point in the history
  • Loading branch information
nhusung committed Apr 26, 2024
1 parent 8348c76 commit 25d7f94
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions bindings/python/build/ffi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This script is run form setup.py (in the project root)"""

import os
import platform
import sys
from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -69,6 +70,7 @@ class LinkMode(Enum):

@staticmethod
def from_env() -> "LinkMode":
"""Read from the OXIDD_PYFFI_LINK_MODE environment variable"""
if container_build:
return LinkMode.STATIC

Expand All @@ -90,6 +92,12 @@ def from_env() -> "LinkMode":
"`static`, `shared-system`, and `shared-dev`.",
)

def crate_type(self) -> str:
"""Associated Rust crate type"""
if self == LinkMode.STATIC:
return "staticlib"
return "cdylib"


build_mode = LinkMode.from_env()

Expand All @@ -101,7 +109,21 @@ def from_env() -> "LinkMode":
if build_mode != LinkMode.SHARED_SYSTEM:
cargo_bin = which("cargo")
print("building crates/oxidd-ffi ...")
run(cargo_bin, "build", f"--profile={profile}", "--package=oxidd-ffi")

# Fix win32 build on win64
cargo_additional_args = []
if platform.system() == "Windows" and sys.maxsize <= 0x1_0000_0000:
cargo_additional_args = ["--target=i686-pc-windows-msvc"]
lib_dir = target_dir / "i686-pc-windows-msvc" / profile

# Use --crate-type=... to avoid missing linker errors when cross-compiling
run(
cargo_bin,
"rustc",
f"--profile={profile}",
"--package=oxidd-ffi",
f"--crate-type={build_mode.crate_type()}",
)

print("running cbindgen ...")
run(
Expand All @@ -113,9 +135,8 @@ def from_env() -> "LinkMode":


def read_cdefs(header: Path) -> str:
"""
Remove C macros and include directives from the include header since CFFI cannot
deal with them.
"""Remove C macros and include directives from the include header since CFFI
cannot deal with them.
"""

res = ""
Expand Down

0 comments on commit 25d7f94

Please sign in to comment.