Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Fix native program loading when solana-runtime is a git or crates.io dependency #5966

Closed
jstarry opened this issue Sep 19, 2019 · 14 comments
Closed
Labels
stale [bot only] Added to stale content; results in auto-close after a week.
Milestone

Comments

@jstarry
Copy link
Contributor

jstarry commented Sep 19, 2019

Problem

The native loader runtime looks for dynamic libraries with a specific filename like this: libsolana_bpf_loader_program.dylib and has been working fine when the runtime dependency is a relative path but breaks in other scenarios. Cargo seems to add an extra hash suffix to dependency filenames when pulling in dependencies from git and crates.io

Proposed Solution

Handle hash suffixed dynamic library file names like this: libsolana_bpf_loader_program-dad324483fd13565.dylib

@mvines
Copy link
Contributor

mvines commented Sep 19, 2019

Cargo seems to add an extra hash suffix to dependency filenames when pulling in dependencies from git and crates.io

What's an example of where/when this happens in practice? This almost feels like a "you're holding it wrong" kind of problem -- eg, stop using a native program, use BPF instead.

@jstarry
Copy link
Contributor Author

jstarry commented Sep 19, 2019

@mvines it happens when testing bpf programs with the solana runtime in a different project. For example, this line was breaking because solana-runtime is a git dependency: https://github.com/solana-labs/solana-voib-demo/pull/10/files#diff-b8c3f81279869c0ce939d0328874bca3R218

Seeing the hash in solana-voib-demo/target/deps:
image

But not in solana/programs/bpf/target/deps:
image (1)

@mvines
Copy link
Contributor

mvines commented Sep 19, 2019

It's not a problem if it's a crates.io dependency though right?

@jstarry
Copy link
Contributor Author

jstarry commented Sep 19, 2019

Just double checked and it is still a problem when using crates.io
Screenshot 2019-09-19 09 09 50

@mvines
Copy link
Contributor

mvines commented Sep 19, 2019

Ah, I see. From cargo’s perspective there could be many versions of that crate in the build. We’re asking it to do something it’s not equipped for. We really want to cargo install those native program shared objects into a known location, but not sure we can get there without hacks because `cargo installs only works for bins.

@jstarry
Copy link
Contributor Author

jstarry commented Sep 19, 2019

@mvines I'm using this hacky workaround for now here: https://github.com/solana-labs/solana-voib-demo/pull/10/files#diff-5e76fee89c5d06973f4f702bc6b21a65R27. We definitely want something better for developers who wish to test their programs using the runtime in the future though.

@jstarry jstarry changed the title Handle dynamic lib filenames with hash suffix in native loader Allow BPF program testing with solana-runtime git or crates.io dependency Sep 19, 2019
@jstarry jstarry changed the title Allow BPF program testing with solana-runtime git or crates.io dependency Allow BPF program testing with a solana-runtime git or crates.io dependency Sep 19, 2019
@mvines
Copy link
Contributor

mvines commented Sep 19, 2019

For this kind of local testing we could statically link the native programs into the runtime, there's really no need for the dynamic loading at all

@jstarry
Copy link
Contributor Author

jstarry commented Sep 20, 2019

@mvines good point, I was running into issues with that approach but have a fix here: #5992

@mvines mvines added this to the Cloud Nine v0.20.0 milestone Sep 23, 2019
@mvines
Copy link
Contributor

mvines commented Oct 14, 2019

@jstarry - think we can call this issue resolved with #5992?

@jstarry
Copy link
Contributor Author

jstarry commented Oct 14, 2019

Sounds good to me. Closing because there's a better approach unblocked by #5992

@jstarry jstarry closed this as completed Oct 14, 2019
@jstarry jstarry changed the title Allow BPF program testing with a solana-runtime git or crates.io dependency Fix native program loading when solana-runtime is a git or crates.io dependency Oct 18, 2019
@jstarry
Copy link
Contributor Author

jstarry commented Oct 18, 2019

Re-opening to avoid this hacky workaround: #6383

@jackcmay
Copy link
Contributor

jackcmay commented Dec 4, 2019

Looks like the consistent messaging from the Rust folks is explicit dynamic linking of direct dependencies is not expected, encouraged, nor supported. Instead the recommendation is to treat these dependencies like any other FFI dependency and pull them in as separate projects (using build scripts for example). We can still keep the programs as direct dependencies for cases where we statically link them (treated as libs by runtime) but I didn't find any viable workarounds to address the file name hash while keeping the dynamically linked programs as direct dependencies.

If we treat the dynamically linked programs as external dependencies I see two options:

  • Pull the programs in as git submodules. This would mean for example that TDS add a submodule for any programs that exist as stand-alone git repo and/or adding the Solana repo as a submodule for programs that live there
  • Use build.rs to clone, build, and install programs into a known location (similar result as the first option)

Not super excited about either of these but they would address this issue. If we went down this path we might also want to split the programs living in Solana out to their own (or a single) repo.

@mvines mvines removed this from the Tofino v0.23.0 milestone Jan 16, 2020
@mvines mvines added this to the The Future! milestone Jan 16, 2020
@stale
Copy link

stale bot commented Jan 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Jan 16, 2021
@stale
Copy link

stale bot commented Jan 24, 2021

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Jan 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stale [bot only] Added to stale content; results in auto-close after a week.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants