rust-portaudio icon indicating copy to clipboard operation
rust-portaudio copied to clipboard

Get build.rs script for Windows working

Open killkrt opened this issue 9 years ago • 10 comments

Hi,

I'm trying to compiling rust-portaudio under Windows 7 SP1 64bit with Rust 1.0.0 (9854143cb 2015-04-02), but I'm getting the following error:

   Compiling portaudio v0.4.0 (file:///C:/temp/rust/rust-portaudio)
     Running `rustc build.rs --crate-name build_script_build --crate-type bin -C
 prefer-dynamic -g --out-dir C:\temp\rust\rust-portaudio\target\debug\build\port
audio-abac5c6e3fd19304 --emit=dep-info,link -L dependency=C:\temp\rust\rust-port
audio\target\debug -L dependency=C:\temp\rust\rust-portaudio\target\debug\deps -
-extern pkg_config=C:\temp\rust\rust-portaudio\target\debug\deps\libpkg_config-c
0e9294bfeefddd9.rlib`
       Fresh pkg-config v0.3.3
       Fresh libc v0.1.6
       Fresh rustc-serialize v0.3.12
   Compiling num v0.1.22
     Running `rustc C:\Users\KillKRT\.cargo\registry\src\github.com-1ecc6299db9e
c823\num-0.1.22\src\lib.rs --crate-name num --crate-type lib -g -C metadata=798f
e7e31b30dacd -C extra-filename=-798fe7e31b30dacd --out-dir C:\temp\rust\rust-por
taudio\target\debug\deps --emit=dep-info,link -L dependency=C:\temp\rust\rust-po
rtaudio\target\debug\deps -L dependency=C:\temp\rust\rust-portaudio\target\debug
\deps --extern rand=C:\temp\rust\rust-portaudio\target\debug\deps\librand-7b0a3a
f7ae4685dc.rlib --extern rustc_serialize=C:\temp\rust\rust-portaudio\target\debu
g\deps\librustc_serialize-70d93d5334da1e4e.rlib -Awarnings`
       Fresh log v0.3.1
       Fresh rand v0.3.7
build.rs:48:9: 48:29 error: this function takes 1 parameter but 0 parameters wer
e supplied [E0061]
build.rs:48         platform::download();
                    ^~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
Could not compile `portaudio`.

Caused by:
  Process didn't exit successfully: `rustc build.rs --crate-name build_script_bu
ild --crate-type bin -C prefer-dynamic -g --out-dir C:\temp\rust\rust-portaudio\
target\debug\build\portaudio-abac5c6e3fd19304 --emit=dep-info,link -L dependency
=C:\temp\rust\rust-portaudio\target\debug -L dependency=C:\temp\rust\rust-portau
dio\target\debug\deps --extern pkg_config=C:\temp\rust\rust-portaudio\target\deb
ug\deps\libpkg_config-c0e9294bfeefddd9.rlib` (exit code: 101)

I've also tried to compile under a MinGW64 environment, but I got the same error.

killkrt avatar Apr 15 '15 21:04 killkrt

@killkrt Thanks for posting the issue! It seems the reason you're running into this error is because no one has yet had a chance to make the build script work with windows (most of us are on macos / linux) - see here for the relevant part that's failing to compile. All the build script does is:

  • Check for an existing installation of portaudio.
  • If it does exist, we are done (this part is already implemented - see here).
  • If it doesn't exist, download and install it, then we are done (this is the unimplemented part). You'll notice that, even once you can get it to compile (by removing the unused _: &Path argument) it will panic straight away if portaudio isn't installed as the windows platform module is unimplemented.

This shouldn't be too tricky to implement at all, if you're up for having a go at it, it'd be well appreciated! (I would have done it by now if I had a windows machine to test on). You can see how the unix platforms do the job in the same module - you basically want to aim to do the same thing but for windows. The instructions for downloading and installing PortAudio can be found here.

mitchmindtree avatar Apr 16 '15 00:04 mitchmindtree

I will try, but consider that I am a beginner in Rust and I don't like developing on Windows, anyway I have to since I'd like to develop a cross-platform DAW.

killkrt avatar Apr 18 '15 15:04 killkrt

This particular error is just because the download function adds an erronous parameter which is fixed by #106. It would also be enough to raise a warning here, because you only need to place a pulseaudio_x64.dll (or the 32bit variant if needed) at the root of your own project and inside of the target/{debug,release}/deps folder (under the name libportaudio.dll if I recall correctly). Not nice, but works fine.

filmor avatar Nov 03 '15 17:11 filmor

This is still the case, many months later :) the script still has the extra parameter for the download function.

As for actually building, it's probably at least safe to use gcc. I haven't looked into the process of actually building it on Windows, though. Will have to check that out.

yupferris avatar Dec 12 '15 23:12 yupferris

After giving it a quick go, the first two issues are this:

  • The latest source is distributed as a tgz, which Windows doesn't have out-of-the-box support for afaik.
  • PortAudio's configure script doesn't appear to work under msys2. I haven't tried with anything else.

yupferris avatar Dec 13 '15 00:12 yupferris

The latest source is distributed as a tgz, which Windows doesn't have out-of-the-box support for afaik.

There are flate2 and tar crates.

kryptan avatar Apr 11 '16 21:04 kryptan

Isn't it possible to include PortAudio as submodule (here is the Git repo) and build it directly in the build script using https://github.com/alexcrichton/gcc-rs ?

lschmierer avatar May 17 '16 12:05 lschmierer

I have made some tests on Windows 10 and I found that a possible (maybe a little tricky solution) could be implemented.

Here you can find a pre-compiled version of Portaudio for Windows.

The archive contains lot of stuff, in particularly there are the LIB and DLL file needed.

For example: for the 64 bit version those files can be found in portaudio-r1891-build.zip\portaudio-r1891-build\lib\x64\Release\. Both of them (portaudio_x64.lib and portaudio_x64.dll) shall be copied in the root folder of the rust-portaudio project, and the LIB file has to be renamed with portaudio.lib.

So an idea could be that the build script asks the user if it has to proceed automatically, then it downloads the ZIP file, extracts it in a temp folder and copies the right stuff in the right place.

Do you think it's to tricky or it could be a solution?

killkrt avatar Aug 19 '16 20:08 killkrt

Fix this. It's been 16 months.

ottworks avatar Aug 22 '16 21:08 ottworks

I have pkg-config installed on my Windows machine, but I decided to take a look at build.rs out of curiosity about how rust-portaudio handles a lack of pkg-config on Windows. I will test later this weekend, hopefully.

You only need to place a pulseaudio_x64.dll (or the 32bit variant if needed) at the root of your own project and inside of the target/{debug,release}/deps folder (under the name libportaudio.dll if I recall correctly).

I think this is a decent, low-impact workaround for Windows users without pkg-config. Perhaps it can be improved adding an (Windows-only?) env variable that specifies a path where to look for a portaudio as well, and fallback to target/{debug,release}/deps (since that will be cleaned up by cargo clean).

Right now, the filename that build.rs appears to be hardcoded to libportaudio.a. This could be changed to libportaudio.dll with a cfg platform branch.

However, from what I can tell without running it, building rust-portaudio-sys without pkg-config installed is completely broken on Windows, even if libportaudio.a is supplied in the correct directory. If there is a match[https://github.com/RustAudio/rust-portaudio/blob/master/rust-portaudio-sys/build.rs#L52] for the library in Cargo's OUT_DIR, print_libs is unconditionally called, which panics on Windows. Perhaps print_libs on Windows should manually print out the cargo strings that pkg-config-rs normally would.

Thoughts/comments/objections welcome :)!

cr1901 avatar Apr 20 '19 13:04 cr1901