Skip to content
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

Compile static index.node #360

Closed
fyn-dev opened this issue Sep 26, 2018 · 3 comments
Closed

Compile static index.node #360

fyn-dev opened this issue Sep 26, 2018 · 3 comments

Comments

@fyn-dev
Copy link

fyn-dev commented Sep 26, 2018

When i try to change Cargo.toml to

[lib]
crate-type = ["staticlib"]

I getting this error

neon ERR! ENOENT: no such file or directory, open '.../target/debug/libmy_module.so'

but then how to compile index.node as static so all dependencies like glibc linked into index.node?

The problem is that when I run my custom module on AWS Lambda function it complains that

/lib64/libc.so.6: version GLIBC_2.18' not found (required by /var/task/index.node) `

on AMI, which execute my lambda function, installed 2.17 version of GLIBC

So this is super inconvenient to create custom build toolchain for Rust to complies with old glibc 2.17 in addition it may missing some other shared libraries which may require by my module. So I prefer to build static index.node which has everything linked with all dependencies in one file so I can run on the Linux server without relying on shared libraries. How to achieve this?

@kjvalencik
Copy link
Member

Hi! Compiling neon statically is not something that would be easy to accomplish because of linking into the various libraries. Also, glibc is notoriously difficult to build against statically because of things like nss. This is why often statically built linux binaries will use alternative libc like muscl.

Since you are compiling for lambda, can I recommend building in docker? There is a docker image for compiling code to run in lambda that has matching library versions. This is a common problem and not limited to neon development.

#292 (comment)

@ndarilek
Copy link

ndarilek commented Feb 8, 2019

I'm having a related issue I suspect. I'm trying to use a library with a fairly complex dependency chain from a Neon module. Here's my build.rs:

https://gitlab.com/ndarilek/spatialite-sys/blob/master/build.rs

You can see there that I link to all my native dependencies with the form:

    println!("cargo:rustc-link-lib=static=spatialite");

Does this mean I shouldn't use static when building this crate under Neon, so that it links correctly when built as an NPM module? Apologies if that's a silly question--using native modules from Rust is new to me.

If I do in fact need to use dynlib instead of static here, is it possible to detect that the crate is being compiled with Neon to swap them out? I use static because the native libraries are built from vendored sources if the main library isn't found, and part of what I want to do with this NPM module is ensure that the complex dependency chain can build and install alongside the module in an Android/iOS Cordova app. But static linking works fine for Rust-native apps, so I'd like to keep that.

Thanks.

@kjvalencik
Copy link
Member

Unfortunately, this isn't currently possible. This thread provides a few workarounds.

rust-lang/cargo#4881

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants