oxidize-rb / rb-sys

Easily build Ruby native extensions in Rust
https://oxidize-rb.github.io/rb-sys/
Apache License 2.0
219 stars 34 forks source link

Duplicate shared libraries in gem store #382

Open gl-yziquel opened 2 months ago

gl-yziquel commented 2 months ago

Hi.

The .so shared library is duplicated in the gem store after installation.

See here for code: https://github.com/gl-yziquel/skeleton_rust_gem/tree/develop Tagged: https://github.com/gl-yziquel/skeleton_rust_gem/releases/tag/gh-rb-sys-380

Having had a look at the Makefile, it seems that the installation process does not clean up. Ideally, I'd have cargo / rust generate the cdylib library, copy or move it to the relevant location, and remove the target/ folder. Why is this not done in the Makefile ? Is there some reason ?

mini-me@virtucon ~/h/s/skeleton_rust_gem (develop)> just wipe install-gem store
[...]
tree `gem env gemdir`/gems/skeleton_rust_gem-0.0.1
/home/mini-me/.local/share/gem/ruby/3.1.0/gems/skeleton_rust_gem-0.0.1
├── Cargo.lock
├── Cargo.toml
├── ext
│   └── skeleton_rust_gem
│       ├── Cargo.toml
│       ├── extconf.rb
│       ├── Makefile
│       ├── skeleton_rust_gem.so
│       ├── src
│       │   └── lib.rs
│       └── target
│           └── CACHEDIR.TAG
├── lib
│   ├── skeleton_rust_gem
│   │   ├── skeleton_rust_gem.so
│   │   └── version.rb
│   └── skeleton_rust_gem.rb
└── README.md

7 directories, 12 files
tree `gem env gemdir`/extensions/x86_64-linux/3.1.0/skeleton_rust_gem-0.0.1
/home/mini-me/.local/share/gem/ruby/3.1.0/extensions/x86_64-linux/3.1.0/skeleton_rust_gem-0.0.1
├── gem.build_complete
├── gem_make.out
├── mkmf.log
└── skeleton_rust_gem
    └── skeleton_rust_gem.so

2 directories, 4 files

I'd also be very much interested in the logic internal to rb-sys which allows to construct the lib/skeleton_rust_gem portion of the lib/skeleton_rust_gem/skeleton_rust_gem.so path. A quick walkthrough through what happens to determine the exact location of that path would matter quite a bit to me.

Best.