From b09522e8256953286187cc0981c3a89504844e9e Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 21 Jul 2021 11:54:56 +0800 Subject: [PATCH 1/4] Fix `RustExtension.install_script` --- setuptools_rust/extension.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools_rust/extension.py b/setuptools_rust/extension.py index 59faf02b..cf73fa9e 100644 --- a/setuptools_rust/extension.py +++ b/setuptools_rust/extension.py @@ -184,7 +184,7 @@ def install_script(self, ext_path): dirname, name = os.path.split(ext_path) file = os.path.join(dirname, "_gen_%s.py" % name) with open(file, "w") as f: - f.write(TMPL.format({"name": name})) + f.write(TMPL.format(name=name)) TMPL = """ From c7a32428c464e141b8abba10ec21468007ce94a3 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 21 Jul 2021 13:39:26 +0800 Subject: [PATCH 2/4] Add exec binding example --- examples/hello-world/Cargo.lock | 7 +++++++ examples/hello-world/Cargo.toml | 8 ++++++++ examples/hello-world/MANIFEST.in | 2 ++ examples/hello-world/hello_world/__init__.py | 0 examples/hello-world/setup.py | 12 ++++++++++++ examples/hello-world/src/main.rs | 3 +++ examples/hello-world/tox.ini | 10 ++++++++++ 7 files changed, 42 insertions(+) create mode 100644 examples/hello-world/Cargo.lock create mode 100644 examples/hello-world/Cargo.toml create mode 100644 examples/hello-world/MANIFEST.in create mode 100644 examples/hello-world/hello_world/__init__.py create mode 100644 examples/hello-world/setup.py create mode 100644 examples/hello-world/src/main.rs create mode 100644 examples/hello-world/tox.ini diff --git a/examples/hello-world/Cargo.lock b/examples/hello-world/Cargo.lock new file mode 100644 index 00000000..e7cecae9 --- /dev/null +++ b/examples/hello-world/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "hello-world" +version = "0.1.0" diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world/Cargo.toml new file mode 100644 index 00000000..718e93eb --- /dev/null +++ b/examples/hello-world/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "hello-world" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/examples/hello-world/MANIFEST.in b/examples/hello-world/MANIFEST.in new file mode 100644 index 00000000..7c68298b --- /dev/null +++ b/examples/hello-world/MANIFEST.in @@ -0,0 +1,2 @@ +include Cargo.toml +recursive-include src * diff --git a/examples/hello-world/hello_world/__init__.py b/examples/hello-world/hello_world/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/hello-world/setup.py b/examples/hello-world/setup.py new file mode 100644 index 00000000..f20bfba8 --- /dev/null +++ b/examples/hello-world/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup +from setuptools_rust import Binding, RustExtension + +setup( + name="hello-world", + version="1.0", + rust_extensions=[ + RustExtension("hello_world.hello_world", binding=Binding.Exec, script=True) + ], + # rust extensions are not zip safe, just like C-extensions. + zip_safe=False, +) diff --git a/examples/hello-world/src/main.rs b/examples/hello-world/src/main.rs new file mode 100644 index 00000000..e7a11a96 --- /dev/null +++ b/examples/hello-world/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/examples/hello-world/tox.ini b/examples/hello-world/tox.ini new file mode 100644 index 00000000..8d8ec646 --- /dev/null +++ b/examples/hello-world/tox.ini @@ -0,0 +1,10 @@ +[tox] +requires = + setuptools-rust @ file://{toxinidir}/../../ + +[testenv] +description = Run the unit tests under {basepython} +deps = + setuptools-rust @ file://{toxinidir}/../../ +commands = hello_world {posargs} +passenv = * From e9e48d72a9efc0397474ec0a5fe071fa7bc4965b Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 21 Jul 2021 13:46:33 +0800 Subject: [PATCH 3/4] Make directories for exec binding extension --- setuptools_rust/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index f6bf66e1..266def5b 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -386,11 +386,12 @@ def install_extension(self, ext: RustExtension, dylib_paths): # remove python3 extension (i.e. cpython-36m) ext_path, _ = os.path.splitext(ext_path) + os.makedirs(os.path.dirname(ext_path), exist_ok=True) ext.install_script(ext_path) else: ext_path = self.get_dylib_ext_path(ext, target_fname) + os.makedirs(os.path.dirname(ext_path), exist_ok=True) - os.makedirs(os.path.dirname(ext_path), exist_ok=True) shutil.copyfile(dylib_path, ext_path) if sys.platform != "win32" and not debug_build: From 9037136a76acfd85a8b23f512b4e6d7462bc08f5 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 21 Jul 2021 14:52:27 +0800 Subject: [PATCH 4/4] Update changelog for #154 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3507a25..4d45842a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Fixed - Use info from sysconfig when cross-compiling. [#139](https://github.com/PyO3/setuptools-rust/pull/139) - Put Rust extension module binary under `build/lib.*` directory. [#150](https://github.com/PyO3/setuptools-rust/pull/150) +- Fix `Exec` binding with console scripts. [#154](https://github.com/PyO3/setuptools-rust/pull/154) ## 0.12.1 (2021-03-11) ### Fixed