bson_ext gem install fails on macOS

I found a better solution, when you install the gem add this at the end

-- --with-cflags="-Wno-error=implicit-function-declaration"

This worked for me on MacOS 11.2.

gem install bson_ext -v '1.5.1' --source '' -- --with-cflags="-Wno-error=implicit-function-declaration"

1.5.1 is 9 years old, so there's no reason to believe that it should work. And, indeed, it also fails for me with the same error (Big Sur / 2.7.1 and 2.8.0).

That being said, if you 100% insist on doing this, and have no alternatives such as changing employers and/or a promising career in software archaeology to fall back on, try this:

Go to the folder indicated in the error message, /Users/lukasz/.rvm/gems/ruby-2.6.5/gems/bson_ext-1.5.1 for inspection.

From there, go to ext/cbson and edit the file bson_buffer.h.

You need to insert one line, near to the top of the file:

/* A buffer */
typedef struct bson_buffer* bson_buffer_t;
/* A position in the buffer */
typedef int bson_buffer_position;

int bson_buffer_get_max_size(bson_buffer_t buffer); 

 /* Allocate and return a new buffer.
 * Return NULL on allocation failure. */
bson_buffer_t bson_buffer_new(void);

run make in that folder. It should work with just a few warnings.

After that, you still need to install it. Check gem help install for details on the process. This is following its instructions:

@ in bson_ext-1.5.1 $ gem spec ../../cache/bson_ext-1.5.1.gem --ruby > ../../specifications/bson_ext-1.5.1.gemspec

And, indeed:

@ in bson_ext-1.5.1 $ gem list bson_ext
*** LOCAL GEMS ***
bson_ext (1.5.1)

Note that this was in the "original" folder again.

Even after that, just doing requite 'bson_ext' does not work for me and require 'bson' complains about it missing. According to that error message, you might succeed by moving–and I want to be very specific here–something, somewhere. No guarantee this will actually work. Probably not.