ruby/spec/bundler/realworld/ffi_spec.rb
David Rodríguez 65612dbb38 [rubygems/rubygems] Fix daily CI
Platform specific versions of ffi-1.17.2 are not compatible with Ruby
3.5, so Bundler fails to resolve in Ruby 3.5 using recorded VCR
responses.

Use the generic version of ffi-1.17.2, which should work for all rubies,
consistently to fix that.

a192f7e35d
2025-08-04 09:27:51 +09:00

57 lines
1.2 KiB
Ruby

# frozen_string_literal: true
RSpec.describe "loading dynamically linked library on a bundle exec context", realworld: true do
it "passes ENV right after argv in memory" do
create_file "foo.rb", <<~RUBY
require 'ffi'
module FOO
extend FFI::Library
ffi_lib './libfoo.so'
attach_function :Hello, [], :void
end
FOO.Hello()
RUBY
create_file "libfoo.c", <<~'C'
#include <stdio.h>
static int foo_init(int argc, char** argv, char** envp) {
if (argv[argc+1] == NULL) {
printf("FAIL\n");
} else {
printf("OK\n");
}
return 0;
}
#if defined(__APPLE__) && defined(__MACH__)
__attribute__((section("__DATA,__mod_init_func"), used, aligned(sizeof(void*))))
#else
__attribute__((section(".init_array")))
#endif
static void *ctr = &foo_init;
extern char** environ;
void Hello() {
return;
}
C
in_bundled_app "gcc -g -o libfoo.so -shared -fpic libfoo.c"
install_gemfile <<-G
source "https://rubygems.org"
gem 'ffi', force_ruby_platform: true
G
bundle "exec ruby foo.rb"
expect(out).to eq("OK")
end
end