Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Test importing built library#7

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timkpaine merged 1 commit intomainfromtkp/test
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
5 changes: 5 additions & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,12 @@ __pycache__/
*$py.class

# C extensions
*.a
*.so
*.obj
*.dll
*.exp
*.lib

# Distribution / packaging
.Python
Expand Down
1 change: 1 addition & 0 deletionshatch_cpp/plugin.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,6 +49,7 @@ def initialize(self, version: str, _: dict[str, t.Any]) -> None:
for command in build_plan.commands:
self._logger.info(command)
build_plan.execute()
build_plan.cleanup()

# build_kwargs = config.build_kwargs
# if version == "editable":
Expand Down
30 changes: 23 additions & 7 deletionshatch_cpp/structs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,8 @@

from dataclasses import dataclass, field
from os import environ, system
from sys import platform as sys_platform
from pathlib import Path
from sys import executable, platform as sys_platform
from sysconfig import get_path
from typing import Literal

Expand DownExpand Up@@ -80,7 +81,7 @@ def default() -> HatchCppPlatform:
raise Exception(f"Unrecognized toolchain: {CC}, {CXX}")
return HatchCppPlatform(cc=CC, cxx=CXX, platform=platform, toolchain=toolchain)

defget_flags(self, library: HatchCppLibrary) -> str:
defget_compile_flags(self, library: HatchCppLibrary) -> str:
flags = ""
if self.toolchain == "gcc":
flags = f"-I{get_path('include')}"
Expand DownExpand Up@@ -109,20 +110,28 @@ def get_flags(self, library: HatchCppLibrary) -> str:
elif self.toolchain == "msvc":
flags = f"/I{get_path('include')} "
flags += " ".join(f"/I{d}" for d in library.include_dirs)
flags += " /LD"
flags += " " + " ".join(library.extra_compile_args)
flags += " " + " ".join(library.extra_link_args)
flags += " " + " ".join(library.extra_objects)
flags += " " + " ".join(f"{lib}.lib" for lib in library.libraries)
flags += " " + " ".join(f"/LIBPATH:{lib}" for lib in library.library_dirs)
flags += " " + " ".join(f"/D{macro}" for macro in library.define_macros)
flags += " " + " ".join(f"/U{macro}" for macro in library.undef_macros)
flags += f" /Fo{library.name}.pyd"
flags += " /EHsc /DWIN32 /LD"
flags += f" /Fo:{library.name}.obj"
flags += f" /Fe:{library.name}.pyd"
flags += " /link /DLL"
if (Path(executable).parent / "libs").exists():
flags += f" /LIBPATH:{str(Path(executable).parent / 'libs')}"
flags += " " + " ".join(f"{lib}.lib" for lib in library.libraries)
flags += " " + " ".join(f"/LIBPATH:{lib}" for lib in library.library_dirs)
# clean
while flags.count(" "):
flags = flags.replace(" ", " ")
return flags

def get_link_flags(self, library: HatchCppLibrary) -> str:
flags = ""
return flags


@dataclass
class HatchCppBuildPlan(object):
Expand All@@ -133,11 +142,18 @@ class HatchCppBuildPlan(object):
def generate(self):
self.commands = []
for library in self.libraries:
flags = self.platform.get_flags(library)
flags = self.platform.get_compile_flags(library)
self.commands.append(f"{self.platform.cc} {' '.join(library.sources)} {flags}")
return self.commands

def execute(self):
for command in self.commands:
system(command)
return self.commands

def cleanup(self):
if self.platform.platform == "win32":
for library in self.libraries:
temp_obj = Path(f"{library.name}.obj")
if temp_obj.exists():
temp_obj.unlink()
8 changes: 7 additions & 1 deletionhatch_cpp/tests/test_project_basic.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
from os import listdir
from pathlib import Path
from shutil import rmtree
from subprocess import check_output
from sys import platform
from sys importpath,platform


class TestProject:
Expand All@@ -20,3 +21,8 @@ def test_basic(self):
assert "extension.pyd" in listdir("hatch_cpp/tests/test_project_basic/basic_project")
else:
assert "extension.so" in listdir("hatch_cpp/tests/test_project_basic/basic_project")
here = Path(__file__).parent / "test_project_basic"
path.insert(0, str(here))
import basic_project.extension

assert basic_project.extension.hello() == "A string"
Loading

[8]ページ先頭

©2009-2025 Movatter.jp