diesel-rs / diesel

A safe, extensible ORM and Query Builder for Rust
https://diesel.rs
Apache License 2.0
12.76k stars 1.07k forks source link

Installing diesel_cli on Windows : some assembly required #487

Closed Shtong closed 7 years ago

Shtong commented 8 years ago

Hello

I was about to do the Diesel tutorial, but had to do some unexpected work at the "install diesel_cli" step, in order to make diesel_cli actually compile.

The command I wanted to run is: rustup run nightly cargo install diesel_cli

My environment is a Windows 10 x64 with VS14 installed, as well as PostgreSQL 9.6 (installed with the official installer) and the SQlite .dll and .def that I manually downloaded and put into some folder.

While I had several errors, they were all pretty similar to this one (missing .lib input files):

   Compiling diesel_cli v0.8.0
     Running `rustc D:\\Users\\Shtong\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\diesel_cli-0.8.0\\src\\main.rs --crate-name diesel --crate-type bin -C opt-level=3 --cfg feature=\"postgres\" --cfg feature=\"default\" --cfg feature=\"sqlite\" --cfg feature=\"diesel\" -C metadata=29283389226be5db --out-dir D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release --emit=dep-info,link -L dependency=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps --extern chrono=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libchrono-7342810e34d1c30d.rlib --extern diesel=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdiesel-759af232b86b362b.rlib --extern clap=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libclap-8f0c0e13919e3e65.rlib --extern dotenv=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdotenv-695bff8444756e3d.rlib -L D:\\Programs\\Sqlite3`
error: linking with `link.exe` failed: exit code: 1181
  |
  = note: "D:\\Programs\\VisualStudio14\\VC\\bin\\amd64\\link.exe" "/LIBPATH:D:\\Programs\\VisualStudio14\\VC\\lib\\amd64" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.10240.0\\ucrt\\x64" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\8.1\\lib\\winv6.3\\um\\x64" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\diesel.0.o" "/OUT:D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\diesel.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps" "/LIBPATH:D:\\Programs\\Sqlite3" "/LIBPATH:D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libchrono-7342810e34d1c30d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdiesel-759af232b86b362b.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libbyteorder-f3f7821512ca2fd0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libtime-750bfdd52feafcb7.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libpq_sys-d9fc24829db90d4f.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\liblibsqlite3_sys-755891849c290f5c.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum-1fa4854b44bb6a54.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum_iter-50df698bc905252c.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum_integer-52fdddf28cd8e924.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum_traits-92bb90166cd1857c.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdotenv-695bff8444756e3d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libregex-19c946c0da62af0b.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libutf8_ranges-5c6a6dacba3be7ce.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libregex_syntax-c54ab5597cd8541d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libaho_corasick-d1dfd931d7cac82f.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libmemchr-c555f740a543880f.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libclap-8f0c0e13919e3e65.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libunicode_segmentation-e3fd0169850011a0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libterm_size-9fd23557733de795.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libvec_map-d843695eff67d492.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libbitflags-0e272044714c8076.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libunicode_width-bcfd50e6d35d16e0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\liblibc-ad32fde1bd850538.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libansi_term-aa5dcc2affa8dc75.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libstrsim-b42a694875d9a3b0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libthread_local-a3c0092e9fb6507d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libthread_id-bcd46c79a620a618.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libkernel32-df86a08647459244.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libwinapi-0889532d327ff4e2.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_unicode-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-6eb85298.rlib" "pq.lib" "sqlite3.lib" "sqlite3.lib" "sqlite3.lib" "msvcrt.lib" "kernel32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "advapi32.lib" "msvcrt.lib"
  = note: LINK : fatal error LNK1181: cannot open input file 'sqlite3.lib'

error: aborting due to previous error

What I had to do in order to successfully compile:

After compilation was done, I had to copy the following DLLs in my ~/.cargo/bin

I'm not sure if Diesel was designed to build on Windows in the first place (I couldn't find any mention of platform-specific instructions or warnings), but these steps allowed me to build Diesel and successfully run the migrations.

sgrif commented 8 years ago

Is it safe to assume that the location of sqlite3.dll is on your path?

Shtong commented 8 years ago

I did not have it in the path at the time I wrote the issue. I just made another test adding sqlite3 to the path and it allowed me to skip the "add sqlite3 the the LIB envvar" part, although using SQLITE3_LIB_DIR is still required to compile libsqlite3-sys.

sgrif commented 8 years ago

I don't control the libsqlite3-sys project, so you'll have to open an issue with them. The only step that you listed that I can potentially do anything about is the renaming libpq.lib which seems odd to me, and I've never had to do on Windows.

Shtong commented 8 years ago

I'll see if I can find where that lib name (pq.lib) comes from, that will be an occasion to learn rustc! As for sqlite3, since it's not required for the tutorial, maybe the tutorial should be updated to install diesel-cli without sqlite support (replacing cargo install diesel_cli with something like cargo install diesel_cli --features postgres)

(sorry for the close, clicked the wrong button)

sgrif commented 7 years ago

Closing this issue, as any changes to make this easier will happen to https://github.com/sgrif/pq-sys, not Diesel. I will also be releasing a new PG driver early next year which will not depend on libpq, and should make this easier.

viperscape commented 7 years ago

@sgrif I know this is closed, but I am receiving linker errors when building with diesel for postgres. Interesting, I can use the rust-postgres lib without issue. Any news on the new pg driver for diesel? Thanks

spasius commented 7 years ago

Linker takes errors when building with diesel for postgres on Windows 7 64-bit, both stable and nightly. rust-postgres works fine.

gbip commented 7 years ago

I can't build diesel for sqlite on windows 10 64 bit with the stable and the nightly toolchain.

LINK : fatal error LNK1181: cannot open input file 'sqlite3.lib'

I tried adding the sqlite dll in .rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib, but I have no idea how to get sqlite3.

It seems that this link present some steps to correctly setup sqlite3.

spease commented 6 years ago

I'm also getting this error. I was able to generate sqlite3.lib, but I don't know how to set the libpath arguments for the linker.

spease commented 6 years ago

Figured it out.

As admin: choco install sqlite3 cd C:\ProgramData\chocolatey\lib\SQLite\tools lib /def:sqlite3.def /out:sqlite3.lib

As dev user: cd C:\ProgramData\chocolatey\lib\SQLite\tools cargo install --no-default-features --features sqlite

ForsakenHarmony commented 6 years ago

@sgrif what happened to that postgres driver?

martinth commented 6 years ago

Since this page is ranked high when you search for "diesel sqlite windows":

For reference , if you want to install diesl_cli for usage with Sqlite, you:

Not really straightforward if you aren't a Window developer (which I'm not) but this should work 🤞

sgrif commented 6 years ago

@martinth Would love to get that info as a PR to some part of our documentation (not entirely sure where the right place would be)

spease commented 6 years ago

You might be able to simplify those instructions if you use chocolatey to install sqlite. Of course, that assumes you have chocolately installed.

That being said, a cholocatey package that provides the lib would make it virtually painless if you had chocolatey installed. Is there a license-related reason for it not being provided with SQLite?

I can’t help but think there should also be a better way...eg have the application check for the library and generate it using the above commands if needed. But I don’t know enough about the executable format to know if it’s impossible to execute any code before it attempts to load dependant libraries.

shawntabrizi commented 6 years ago

I think the best way to address this issue now is following these instructions:

If you are using a system without an easy way to install sqlite (for example Windows), you can use a bundled version instead:

cargo install diesel_cli --no-default-features --features "sqlite-bundled"

spease commented 6 years ago

This is fantastic

mZbZ commented 5 years ago

Since this page is ranked high when you search for "diesel sqlite windows":

For reference , if you want to install diesl_cli for usage with Sqlite, you:

* download the precompiled Windows binaries from https://sqlite.org/download.html

* extract them to a folder (i.e. `C:\sqlite64`)

* run a cmd terminal with the 64bit msvc toolchain in the path: "Win + R" and execute `%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64`

* `cd C:\sqlite64` and run `lib /def:sqlite3.def /out:sqlite3.lib`

* add  `C:\sqlite64`  to `PATH`

* create an environment variable `SQLITE3_LIB_DIR` also pointing to `C:\sqlite64`

* restart terminal and run `cargo install diesel_cli --no-default-features --features sqlite`

Not really straightforward if you aren't a Window developer (which I'm not) but this should work 🤞

Thanks so much for this

For those looking for help using the gnu toolchain on windows (with MinGW), step 3 isn't necessary and step 4 becomes:

cd C:\sqlite64 and run C:\path\to\MinGW\bin\dlltools.exe -d sqlite3.def -o sqlite3.a

Everything else is the same 😃

johnwaltonvi commented 5 years ago

Thank you guys so much for answering this Result Type Err lol

ScottHuangZL commented 5 years ago
  1. Get mysql connector from: https://downloads.mysql.com/archives/c-c/
  2. Get postgress from : https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
  3. setx MYSQLCLIENT_LIB_DIR "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14"
  4. setx PQ_LIB_DIR "C:\PostgreSQL\12\lib"
  5. Finally you can install diesel client through below: cargo install diesel_cli --no-default-features --features "sqlite-bundled mysql postgres" --force
panstromek commented 4 years ago

I got the same error, but not when building cli, but when building the app. Since this is one of the top results on Google now (even though it's a bit different problem), I'll add that in my case it was enough to just add:

libsqlite3-sys = { version = "...", features = ["bundled"] }

in cargo.toml as noted in https://github.com/diesel-rs/diesel/issues/1647

Kubikx commented 4 years ago

I tried setx PQ_LIB_DIR "C:\Program Files\PostgreSQL\12\lib" even thou it is already in the Path env variable, but cargo install diesel_cli --no-default-features --features postgres still end up with = note: LINK : fatal error LNK1181: cannot open input file 'libpq.lib'

godbrain commented 4 years ago

Over 4 years later and this still doesn't work? Can't get past this... same as kubikx above...

spease commented 4 years ago

Look at @shawntabrizi ’s answer above. Does that help?

EDIT: My bad, Postgres not sqlite

godbrain commented 4 years ago

After many env updates and reboots I got this to work... the setx path has to be correct and Windows rebooted at least once.

godbrain commented 4 years ago

Of course now the diesel command does absolutely nothing. Is there another Rust ORM that works?

fluxxu commented 4 years ago

Of course now the diesel command does absolutely nothing. Is there another Rust ORM that works?

You have to add the folder that contains DLL files to your PATH env. It does nothing because it crashed. If you double click diesel.exe in C:\Users\YourName\.cargo\bin, you'll see the message box says some DLL is missing.

weiznich commented 4 years ago

@godbrain This issue has been closed since more than 4 years, so that is clearly not the right place to ask questions that are basically about your environment. I know that it can be quite hard to setup everything correctly on windows and this turns on google as one of the top results, but commenting on a such an old issue is really not the right way to solve that problem. We a have a quite active gitter channel for this kind of problems, where you can get help without sending a notification to all people subscribed to this issue/repository. Generally speaking: Using WSL is probably the easiest way to get everything working on windows, so if you have trouble figuring out the corresponding linker paths for the microsoft tool chains, use WSL. It's really nothing we have much control over.

Of course now the diesel command does absolutely nothing. Is there another Rust ORM that works?

This comment is borderline hostile, is it does not contain anything somehow related to the original issue you are commenting on or even actionable criticism. Please consider how you talk about the projects of other people in the future. I do not consider this as tolerable behaviour here.

godbrain commented 4 years ago

Thanks @fluxxu , I'll give that a try but I even tried running it directly from that directory.

@weiznich, sorry to spam the group on this old ticket. Unfortunately though running a basic command to get diesel running from the web site instructions still doesn't work after 4 years. If this doesn't run natively on Windows and needs WSL to run that's fine but I don't see that documented anywhere so here I am at this old ticket. It also worries me when I go to the web site and it says copyright 2018 like it's not being maintained. I would like to see this working as I have found an interest in Rust and wanted to set something up with diesel and rocket. I think it would help people in the future who want to use Rust if some of this was noted on the website.

I am currently writing apps in .net core, Phoenix/elixir and laravel/php and was hoping to add Rust as an option. I admit I got a little frustrated with this as I was up until 1am working on it. I could have worded things differently but I really was wondering if this was the only Rust ORM or not.

Thanks for your help on this and I will be more positive in the future.

weiznich commented 4 years ago

@godbrain It does work on windows natively, you just need to figure out some paths/environment variables. Unfortunately we cannot provide exact installation guide there, as those tend be invalid quite fast, because of windows changing things and not having clear standards of how to configure that in a reliable way. (Additionally I do not use windows by myself, so I'm not that much of help there, so I normally just point to our CI (postgres example) as things work there.) To word that a bit differently: I've come from a c/c++ background, there such linker errors are quite common and people know how to fix them for their platform. I'm basically assuming the same thing here as I do not know how to describe this better. So if anyone comes up with some concrete robust cross platform installation description, just submit a PR here.

I could have worded things differently but I really was wondering if this was the only Rust ORM or not.

The question here is what exactly do you consider to be a ORM. There is tql which is something along the lines of a classical ORM. Diesel on the other hand is quite opinionated, so expect that it works differently in some places as other ORM's.

spease commented 4 years ago

@godbrain ’s criticism is totally fair. It was a massive hassle when I tried to get diesel working on Windows, and it reflected very poorly on Rust, with diesel seemingly being the pre-eminent Rust ORM.

I’d consider install instructions to be a prerequisite for providing support for a platform. If diesel has chosen not to provide those, then I think it’s fair to say it doesn’t fully support Postgres on Windows, and it’s not “hostile” to ask if there is an alternative with support.

It’s not scalable for professional or especially side project work for every library to require the user to spend several hours figuring out how the environment is supposed to be set up, or rely on the total unknown of someone on Gitter helping. If I had to do that for every one of the ~20-30 direct dependencies of my current project, I’d never get any actual work done.

weiznich commented 4 years ago

As I feel there are increasingly more people complaining about things and trying to "suggest" me how I should spend my free time working on diesel I think I should clarify how I prioritize my work on diesel:

To comment on a few specific points of @spease comment:

It was a massive hassle when I tried to get diesel working on Windows, and it reflected very poorly on Rust, with diesel seemingly being the pre-eminent Rust ORM.

It's not my "fault" that there are no bigger ORM style crates in rust, so either feel free to write your own and show how much better you can do or try to be constructively here. In the end if this continues I may consider to just work on and use my own private fork of diesel.

I’d consider install instructions to be a prerequisite for providing support for a platform. If diesel has chosen not to provide those, then I think it’s fair to say it doesn’t fully support Postgres on Windows,

I like to disagree. Postgres on windows is a supported platform, as we are testing everything there. It's just not my fault that there are perceived 100 different ways to install dependencies on windows that are all slightly incompatible with each other. I just do not see how it would be possible to write a documentation that covers all of this, without even having access to at least one of those environments. In the end that's the environment the developer has choosen to work in and where I expect them to know how to make things work.

and it’s not “hostile” to ask if there is an alternative with support.

The question itself is not hostile, but the wording. I do not consider: " Is there another Rust ORM that works?" after stating that diesel obviously don't work (without providing information what did not work), as a friendly question. It would be OK, if the statement "Of course now the diesel command does absolutely nothing." contained any information about what exactly does not work or at least how to reproduce that. Without that I take this statement as offence against my previous work (as we test those things and they work there). I at least expect that people assume that we are trying to make things work as easily as possible on all platforms and that maybe the error is in their enviroment and not in diesel itsel.

It’s not scalable for professional or especially side project work for every library to require the user to spend several hours figuring out how the environment is supposed to be set up, or rely on the total unknown of someone on Gitter helping. If I had to do that for every one of the ~20-30 direct dependencies of my current project, I’d never get any actual work done.

So to just clarify that: Instead of figuring it out on your own you expect that I spend basically the same time to figure it out for you without knowing anything about your environment? You can do that, but don't expect any help from me then. There is not much more that we can tell here than: You need to provide the libraries present in the linker error, which is already written on the web page. How that is done depends on to much things in your environment, that we cannot be much more concrete.

If you really want that certain things happen, there are a few possible ways to get there:

That's my last comment on this kind of issues, in future I will just unsubscribe those, and let them be. It's better for my health.

I know this all may sound quite harsh, but it needs to be said. So to end this with something actionable for all those that are complaining: Here is the source code for the web page, the other documentation is written in this repository. Code for actually linking libpq is here. Feel free to submit a concrete improvement instead of just complaining.

godbrain commented 4 years ago

Hello @weiznich, I never meant to cause a big problem here. I also assumed a lot of people were working on this project and not mostly just yourself. I understand you don’t have all your free time to support this. I don’t understand how anyone really has time to support so many open source projects to be honest. I was just hoping to get a web environment up and running on Rust and ran into a few issues on the way. Since I have environments to run this for Windows and Linux I created an install “helper” doc for Windows 10 and have attached it. I will leave it to you if you want it added to the repo. Thank You dieselinstallonwin10.pdf

samda4 commented 4 years ago
  1. download sqlite3.lib file
  2. C:\Users...rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\ add sqlite3.lib file this directory
grandsilence commented 4 years ago

Solution

  1. Build missing lib file (sqlite3.lib / libpq.lib)
  2. Copy lib file to C:\Users\User\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib

Missing sqlite3.lib (by default)

  1. Download source from source (https://www.sqlite.org/download.html)

    For example: source https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip

  2. Download binary from binary

    For example: binary https://www.sqlite.org/2020/sqlite-dll-win64-x64-3310100.zip

  3. Extract both archives to the same directory

  4. Open Developer Command Prompt for VS 2017 by typing Developer Command in Windows Search

  5. Go to directory where you've extracted source code and binary files (via opened cmd)

  6. Run lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64

Missing libpq.lib

When using command:

cargo install diesel_cli --no-default-features --features postgres
  1. Download binaries archive from postgreSQL binaries.
  2. Unpack lib file pgsql/lib/libpq.lib to your cargoup lib dir
    (C:\Users\User\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib)
spease commented 4 years ago

@weiznich Sorry my reply caused such frustration. Note that I hadn't even worked for the company I had been trying to use diesel at for a year, and we opted not to use Rust. Processing tens of GB for biopharma research was nonviable due to #1775, and there was strong internal inertia for C++ that I doubt any Rust solution could have overcome. Note also that I posted a solution for sqlite in this ticket when I found one. What I would usually expect is that the configuration used for the test harness would be documented as the "supported solution" so the work involved to figure it out would have already been done, and this would also have the nice property of validating the supported method whenever the tests are run.

Thanks for all the work you're doing.

ta32 commented 4 years ago

I had some trouble getting diesel to work with windows with sqlite. In the end this is what i did i think it's probably the simplest for most windows users.

installed diesel cli cargo install diesel_cli --no-default-features --features "sqlite-bundled"

follow other instructions on setting up a project ie creating an env file, and running diesel setup.

use the following dependencies for your project dotenv = "0.15.0" libsqlite3-sys = { version = "^0", features = ["bundled"] } diesel = {version = "^1.4.5", features = ["sqlite"]}

oddly the project built without libsqlite3-sys = { version = "^0", features = ["bundled"] }, however when your ran cargo test it failed to link. I think somehow cargo build was finding the sqlite lib from the installation of diesel_cli or somewhere else in my system (i am not sure). With these instructions you don't need to install anything on your system or mess with the path!

Hope others find this useful

Edit: version numbers are not important - use whatever is required for your project and refer to the current docs

bugproof commented 4 years ago

I think this shouldn't be closed until there is a real fix for this, even something simple like adding windows instructions to the docs. Setting environment variables like PQ_LIB_DIR. Pretty much everyone who wants to try diesel will have this problem.

weiznich commented 4 years ago

@bugproof As already mentioned multiple times: We won't add OS specific instructions because we don't have the resources to keep them up to date. Other than that: Feel free to submit improvements here

bugproof commented 4 years ago

@weiznich

We won't add OS specific instructions because we don't have the resources to keep them up to date

I think one or two OS specific notes won't hurt anyone. IMO Getting started should be straightforward, not running into errors and googling for solutions.

weiznich commented 4 years ago

@bugproof Discussing the same thing again and again won't change my decision here. I cannot keep that up to date, I cannot maintain OS specific instructions. If someone volunteers in doing so feel free to do that, but I won't. Especially Instructions for windows are hard to maintain for me as I do not have access to a windows machine and there are to many variants to install dependencies to list all. That said I will unsubscribe from this issue now, as this is solved from my point of view and I do not want to have the same discussion over and over again.

weiznich commented 3 years ago

@JulianRuiseco I'm not sure what you expect to hear here. It's definitively not a good way to get support for something by just commenting with complaints on old issues. Using diesel on windows is definitively supported (see the CI config for a known working installation variant), but at least I do not have access to a windows PC and do not want to spend my free time on fixing other peoples broken environments caused by installing dependencies from who knows where. If you expectation, then yes you shouldn't use diesel on windows.

xil3 commented 11 months ago
  1. download sqlite3.lib file
  2. C:\Users...rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\ add sqlite3.lib file this directory

This was actually the only thing that worked for me, for anyone else having this issue.

Update: Let me clarify that my issue was not related to diesel_cli, but when compiling the app itself.

sudo-sein commented 6 months ago
  1. Get mysql connector from: https://downloads.mysql.com/archives/c-c/
  2. Get postgress from : https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
  3. setx MYSQLCLIENT_LIB_DIR "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14"
  4. setx PQ_LIB_DIR "C:\PostgreSQL\12\lib"
  5. Finally you can install diesel client through below: cargo install diesel_cli --no-default-features --features "sqlite-bundled mysql postgres" --force

This should be top comment

andreyshedko commented 5 months ago

@Kubikx My solution for this problem was adding entry to root .cargo/config.toml

[target.x86_64-pc-windows-msvc.pq]
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\13\\lib"]
rustc-link-lib = ["libpq"]

Although I'm still looking for these solution of this error: error while loading shared libraries: api-ms-win-crt-heap-l1-1-0.dll: cannot open shared object file: No such file or directory But I know that this dll exists and installed.