-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bundled library and generated cffi module paths for nested packag…
…es (#16)
- Loading branch information
Showing
10 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
example/_native* |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from . import _native | ||
|
||
|
||
def test(): | ||
point = _native.lib.example_get_origin() | ||
return (point.x, point.y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "example" | ||
version = "0.1.0" | ||
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"] | ||
|
||
[lib] | ||
name = "example" | ||
crate-type = ["cdylib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
typedef struct { | ||
float x; | ||
float y; | ||
} Point; | ||
|
||
typedef enum { | ||
FOO_A = 1, | ||
FOO_B = 2, | ||
FOO_C = 3 | ||
} Foo; | ||
|
||
Point example_get_origin(void); | ||
void example_print_foo(Foo *); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#[repr(C)] | ||
pub struct Point { | ||
pub x: f32, | ||
pub y: f32, | ||
} | ||
|
||
#[repr(u32)] | ||
pub enum Foo { | ||
A = 1, | ||
B, | ||
C | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn example_get_origin() -> Point { | ||
Point { x: 0.0, y: 0.0 } | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn example_print_foo(foo: *const Foo) { | ||
println!("{}", match *foo { | ||
Foo::A => "a", | ||
Foo::B => "b", | ||
Foo::C => "c", | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from setuptools import setup, find_packages | ||
|
||
def build_native(spec): | ||
# Step 1: build the rust library | ||
build = spec.add_external_build( | ||
cmd=['cargo', 'build', '--release'], | ||
path='./rust' | ||
) | ||
|
||
# Step 2: add a cffi module based on the dylib we built | ||
# | ||
# We use lambdas here for dylib and header_filename so that those are | ||
# only called after the external build finished. | ||
spec.add_cffi_module( | ||
module_path='example.nested._native', | ||
dylib=lambda: build.find_dylib('example', in_path='target/release'), | ||
header_filename=lambda: build.find_header('example.h', in_path='.'), | ||
rtld_flags=['NOW', 'NODELETE'] | ||
) | ||
|
||
|
||
setup( | ||
name='example', | ||
version='0.0.1', | ||
packages=find_packages(), | ||
include_package_data=True, | ||
zip_safe=False, | ||
platforms='any', | ||
install_requires=[ | ||
'milksnake', | ||
], | ||
milksnake_tasks=[ | ||
build_native, | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters