vercel-community / rust

🦀 Rust runtime for ▲ Vercel Serverless Functions

Home Page:https://rust-runtime.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot access shared libraries

mike-engel opened this issue · comments

Note: This was transferred from the official now-builders repo.

I'm using a library that uses pq-sys, which tries to load libpq at runtime. Whenever the lambda is invoked, it encounters this error:

/var/task/bootstrap: error while loading shared libraries: libpq.so.5:
cannot open shared object file: No such file or directory

I'm not familiar with this stuff, but I managed to verify that:

  • libpq.so.5 is located in /usr/lib64
  • LD_LIBRARY_PATH includes /usr/lib64
  • PQ_LIB_DIR includes /usr/lib64

It seems the lambda is not able access shared libraries at runtime. Here's an example deployment for reference.

Bummer about musl being more difficult than anticipated. I'm not super familiar with AWS lambdas, is accessing shared libraries possible or is static linking the only way forward?

It really doesn't matter to me how it happens, but it would be wonderful if I could get rust to talk to a Postgres (Edit: Actually, I'm using MySQL instead, though the same concept applies, ha) database in any way at all. Should I abandon diesel and look for a different solution, or is this issue something that can be fixed?

Thanks for your continued help with this!

One option I could see is to include shared libraries in the build as static files. You would have to change the environment variables/rust configuration to look in that place rather than in the normal locations, but that could be an alternative.

Admittedly I don't have a ton of systems knowledge here, so I don't know why diesel requires static links vs. dynamic ones (or maybe that was just the solution for now lambdas).

Yeah that was just the solution for the lambdas, dynamic links work just fine in other environments.

Thanks for the suggestion, I'm going to try that for a while. Bummer that the iteration loop is just so long, compiling for 5 minutes just to get the same error as before is starting to get soul crushing ha.

@jacobmischka I totally understand that! I've been there many times before. Hopefully #1 will help 😄

Hey, that was significantly easier than I thought, thanks so much for your direction.

I was able to get it to successfully use the libraries by including a lib directory containing the necessary .so files, and using the following now.json:

{
	"version": 2,
	"builds": [
		{
			"src": "Cargo.toml",
			"use": "now-rust",
			"config": {
				"includeFiles": [
					"lib/**",
				]
			}
		}
	],
	"env": {
		"LD_LIBRARY_PATH": "lib/"
	},
	"build": {
		"env": {
			"MYSQLCLIENT_LIB_DIR": "lib",
			"LD_LIBRARY_PATH": "lib/"
		}
	}
}

Wonderful! So glad it worked for you and that we have a nice alternative. I'll add it to the README soon. Thanks for testing!