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

Windows の nanobind のビルドが通らないのを修正する #73

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions fix_nanobind_nb_func.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# https://github.com/wjakob/nanobind/issues/613 の問題を修正するパッチ
# 以下のように利用する
#
# ```
# cp include/nanobind/nb_func.h include/nanobind/nb_func.h.old
# patch < fix_nanobind_nf_func.patch
# ```
#
--- include/nanobind/nb_func.h.old 2024-07-19 07:55:35.166432900 +0900
+++ include/nanobind/nb_func.h 2024-07-19 07:50:33.812445300 +0900
@@ -199,14 +199,24 @@

PyObject *result;
if constexpr (std::is_void_v<Return>) {
+#if defined(_WIN32)
+ cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...);
+#else
cap->func(in.template get<Is>().operator cast_t<Args>()...);
+#endif
result = Py_None;
Py_INCREF(result);
} else {
+#if defined(_WIN32)
+ result = cast_out::from_cpp(
+ cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...),
+ policy, cleanup).ptr();
+#else
result = cast_out::from_cpp(
cap->func((in.template get<Is>())
.operator cast_t<Args>()...),
policy, cleanup).ptr();
+#endif
}

if constexpr (Info::keep_alive)
66 changes: 54 additions & 12 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,35 @@ def get_build_platform() -> PlatformTarget:
return PlatformTarget(os, osver, arch)


def apply_patch(patch, dir, depth):
with cd(dir):
if platform.system() == "Windows":
cmd(
[
"git",
"apply",
f"-p{depth}",
"--ignore-space-change",
"--ignore-whitespace",
"--whitespace=nowarn",
patch,
]
)
else:
with open(patch) as stdin:
cmd(["patch", f"-p{depth}"], stdin=stdin)


# 標準出力をキャプチャするコマンド実行。シェルの `cmd ...` や $(cmd ...) と同じ
def cmdcap(args, **kwargs):
# 3.7 でしか使えない
# kwargs['capture_output'] = True
kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.PIPE
kwargs["encoding"] = "utf-8"
return cmd(args, **kwargs).stdout.strip()


BASE_DIR = os.path.abspath(os.path.dirname(__file__))


Expand Down Expand Up @@ -657,21 +686,22 @@ def install_deps(
}
install_openh264(**install_openh264_args)

# nanobind にパッチを適用する
nanobind_include_dir = cmdcap([sys.executable, "-m", "nanobind", "--include_dir"])
if not os.path.exists(os.path.join(nanobind_include_dir, "nanobind", "nb_func.h.old")):
shutil.copyfile(
os.path.join(nanobind_include_dir, "nanobind", "nb_func.h"),
os.path.join(nanobind_include_dir, "nanobind", "nb_func.h.old"),
)
patch = os.path.join(BASE_DIR, "fix_nanobind_nb_func.patch")
with cd(nanobind_include_dir):
apply_patch(patch, nanobind_include_dir, 1)


def cmake_path(path: str) -> str:
return path.replace("\\", "/")


# 標準出力をキャプチャするコマンド実行。シェルの `cmd ...` や $(cmd ...) と同じ
def cmdcap(args, **kwargs):
# 3.7 でしか使えない
# kwargs['capture_output'] = True
kwargs["stdout"] = subprocess.PIPE
kwargs["stderr"] = subprocess.PIPE
kwargs["encoding"] = "utf-8"
return cmd(args, **kwargs).stdout.strip()


def main():
build_platform = get_build_platform()

Expand Down Expand Up @@ -755,7 +785,10 @@ def main():
]

# Windows 以外の、クロスコンパイルでない環境では pyi ファイルを生成する
if target_platform.os != "windows" and build_platform.package_name == target_platform.package_name:
if (
target_platform.os != "windows"
and build_platform.package_name == target_platform.package_name
):
cmake_args.append("-DSORA_GEN_PYI=ON")

sora_src_dir = os.path.join("src", "sora_sdk")
Expand All @@ -768,7 +801,16 @@ def main():
mkdir_p(sora_build_dir)
with cd(sora_build_dir):
cmd(["cmake", BASE_DIR, *cmake_args])
cmd(["cmake", "--build", ".", "--config", configuration, f"-j{multiprocessing.cpu_count()}"])
cmd(
[
"cmake",
"--build",
".",
"--config",
configuration,
f"-j{multiprocessing.cpu_count()}",
]
)

for file in os.listdir(sora_src_dir):
if file.startswith("sora_sdk_ext.") and (
Expand Down
Loading