Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upWindows support #10
Comments
dgrunwald
added
the
enhancement
label
May 26, 2015
This comment has been minimized.
This comment has been minimized.
|
I've started working on at least getting the build script to be correct. |
This comment has been minimized.
This comment has been minimized.
|
Have you had any success linking against the official python27.dll on Windows? |
This comment has been minimized.
This comment has been minimized.
|
python27-sys appeared to compile fine, but there may still be issues that I didn't see because I didn't try to get rust-cpython itself to work yet. some interesting comments here about what .rlibs actually contain: rust-lang/rust#25820 so would make sense that the issues would only come up when trying to actually create an executable, which I didn't do. also some chatter here: https://mail.mozilla.org/pipermail/rust-dev/2014-July/010702.html |
This comment has been minimized.
This comment has been minimized.
|
okay, so once I moved the python.org's python27.dll into C:\Program Files\Rust nightly 1.2\bin\rustlib\x86_64-pc-windows-gnu\lib, the linker was able to locate but it rejects it with this when running note: ld: skipping incompatible C:\Program Files\Rust nightly 1.2\bin\rustlib\x86_64-pc-windows-gnu\lib/python27.dll when searching for -lpython27 I suspect this is because I have a 64-bit rust with a 32-bit python, but the error message is opaque. |
This comment has been minimized.
This comment has been minimized.
|
I tried using a
But those symbols are exported by the .lib:
|
This comment has been minimized.
This comment has been minimized.
|
The missing symbols seem to always be global variables. Looks like this is caused by missing |
dgrunwald
added a commit
that referenced
this issue
Jun 27, 2015
This comment has been minimized.
This comment has been minimized.
yunge
commented
Aug 5, 2015
|
Hi, I get some issues when try the test code in windows, so windows support is not finished yet? E:\dev\msys32\home\fu.cargo\registry\src\github.com-121aea75f9ef2ce2\cpython-0.0.3\src/python.rs:156: undefined reference to `_Py_NoneStruct' |
This comment has been minimized.
This comment has been minimized.
|
For the msys-version of rust (x86_64-pc-windows-gnu), I have no idea how to get the msys linker to link against pythonXY.dll. For the msvc-version of rust (x86_64-pc-windows-msvc), I think it's currently impossible to link against pythonXY.dll due to Rust's lack of I've given up on Windows support for now. Feel free to dig deeper into the linker troubles. |
dgrunwald
added
the
help wanted
label
Aug 5, 2015
This comment has been minimized.
This comment has been minimized.
yunge
commented
Aug 6, 2015
|
Ok, I'll play it with linux. Anyway, thanks for the cool project! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The #[linked_from] attribute might help here. |
This comment has been minimized.
This comment has been minimized.
Eh2406
commented
Jan 26, 2016
|
Is this still "given up" on? |
This comment has been minimized.
This comment has been minimized.
Yes. Here's a small test case demonstrating where I'm stuck: #![feature(linked_from)]
use std::ffi;
use std::os::raw::c_char;
type PyObject = i32;
#[linked_from = "python27"]
extern "C" {
fn Py_Initialize() -> ();
static mut _Py_TrueStruct: PyObject;
fn PyObject_Str(o: *mut PyObject) -> *mut PyObject;
fn PyString_AsString(string: *mut PyObject) -> *mut c_char;
}
fn main() {
unsafe {
Py_Initialize();
println!("{:?}", ffi::CStr::from_ptr(PyString_AsString(PyObject_Str(&mut _Py_TrueStruct))));
}
}Compile:
Note that the function calls don't give linker errors, only the Explicitly telling rustc that python27 is a .dll (using Note that the .lib and .dll do contain this symbol:
The equivalent C program:
Compile:
Note that if I leave out the
So the problem is that I can't find a way to convince rustc to mark the imported symbols as |
This comment has been minimized.
This comment has been minimized.
Eh2406
commented
Apr 10, 2016
•
|
Just some notes to save some time next time I look into this. I searched rust git for rust-lang/rfcs#1061: checkbox 2. If any of those move we may get unstuck. |
Eh2406
referenced this issue
Jul 28, 2016
Closed
RFC: Add an `alias` attribute to #[link] and -l #1296
This comment has been minimized.
This comment has been minimized.
retep998
commented
Jul 28, 2016
•
|
The behavior of dllimport with regards to statics in Rust is like this the last time I checked. When referencing an extern static from within the same crate, dllimport is not applied. So basically dllimport is being applied based on whether it is referenced across a crate boundary even though that has absolutely nothing to do with how the static is being linked in. Try not to rely on this behavior though and just push Rust to get it properly fixed. |
This comment has been minimized.
This comment has been minimized.
vadimcn
commented
Jul 28, 2016
|
@dgrunwald: Your code linked just fine using Re extern "C" {
...
#[link_name = "\x01__imp___Py_TrueStruct"]
static imp_Py_TrueStruct: *mut PyObject;
...
}
fn main() {
unsafe {
Py_Initialize();
println!("{:?}", ffi::CStr::from_ptr(PyString_AsString(PyObject_Str(imp_Py_TrueStruct))));
}
}Not pretty, but works. |
This comment has been minimized.
This comment has been minimized.
PJB3005
commented
Nov 4, 2016
|
Any hope of this happening in the near future? I'd absolutely love to use this for a project but if Windows support isn't a thing I'll have to pass. |
This comment has been minimized.
This comment has been minimized.
Eh2406
commented
Nov 4, 2016
|
It is still waiting on rust. The rfc is accepted rust-lang/rfcs#1717 and the trcking ishuw is at rust-lang/rust#37403 I don't think anyone has started implementation. |
This comment has been minimized.
This comment has been minimized.
PJB3005
commented
Nov 4, 2016
|
Alright, thanks for the info. Here's hoping I suppose. |
This comment has been minimized.
This comment has been minimized.
Eh2406
commented
Dec 17, 2016
|
This works on the new nightlies!!! use std::ffi;
use std::os::raw::c_char;
type PyObject = i32;
#[link(name="python27", kind="dylib")]
extern "C" {
fn Py_Initialize() -> ();
static mut _Py_TrueStruct: PyObject;
fn PyObject_Str(o: *mut PyObject) -> *mut PyObject;
fn PyString_AsString(string: *mut PyObject) -> *mut c_char;
}
fn main() {
unsafe {
Py_Initialize();
println!("{:?}",
ffi::CStr::from_ptr(PyString_AsString(PyObject_Str(&mut _Py_TrueStruct))));
}
}I am so excited!!! What are the next steps to getting |
This comment has been minimized.
This comment has been minimized.
|
I'm on it; if everything works as well as my initial tests indicate, I should be able to add Windows support today. |
dgrunwald
added a commit
that referenced
this issue
Dec 17, 2016
dgrunwald
closed this
in
f6ed2bb
Dec 17, 2016
This comment has been minimized.
This comment has been minimized.
Eh2406
commented
Dec 17, 2016
|
Thank you so much! I am stced to try this out! how do I tell cargo where to find my python lib and that |
This comment has been minimized.
This comment has been minimized.
|
The default is Python 3.x, to target Python 2.x, you'll need to use:
If you have |
This comment has been minimized.
This comment has been minimized.
Eh2406
commented
Dec 17, 2016
|
Wow! As usual on this project things are easier and smarter than I thout. :-) I missed that it checked the path to find |
dgrunwald commentedMay 26, 2015
I actually started writing rust-cpython on Windows, but had to give up due to strange issues when linking against the official python binaries. Now that the
x86_64-pc-windows-msvctarget exists, we should give it another try.