-
Notifications
You must be signed in to change notification settings - Fork 136
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 support #10
Comments
I've started working on at least getting the build script to be correct. |
Have you had any success linking against the official python27.dll on Windows? |
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 |
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. |
I tried using a
But those symbols are exported by the .lib:
|
The missing symbols seem to always be global variables. Looks like this is caused by missing |
Due to the linker troubles (#10), we only build the rlib and don't run any tests.
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' |
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. |
Ok, I'll play it with linux. Anyway, thanks for the cool project! |
The #[linked_from] attribute might help here. |
Is this still "given up" on? |
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 |
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. |
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. |
@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. |
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. |
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. |
Alright, thanks for the info. Here's hoping I suppose. |
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 |
I'm on it; if everything works as well as my initial tests indicate, I should be able to add Windows support today. |
Thank you so much! I am stced to try this out! how do I tell cargo where to find my python lib and that |
The default is Python 3.x, to target Python 2.x, you'll need to use:
If you have |
Wow! As usual on this project things are easier and smarter than I thout. :-) I missed that it checked the path to find |
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-msvc
target exists, we should give it another try.The text was updated successfully, but these errors were encountered: