Well this is a first. Trying to resurrect some old Ruby repos but Travis CI is flagging my pushes as Abuse.
oh figures. Ruby 2.5 lacks USHORT2NUM macro, but the C compiler treats undefined macros as undefined symbols. Ruby's C macros are the cruftiest part of the API.
https://github.com/postmodern/digest-crc/issues/13#issuecomment-595118118 recent benchmarks of pure Ruby CRC algorithms vs. the optional C extensions. Looks like a +90% performance improvement across the board 😮
Starting to regret avoiding C extensions for all these years 😕 (although they are still a PITA to write and C is not a safe or secure programming language...)
TIL mkmf's `create_makefile` cannot be called multiple times to generate multiple separate Makefiles, because it's a dumpster fire of global variables...
nm, prototyping my own. Trying to duplicate the make/installation part of the extconf building.
I'm really curious if there's an example out there of building Ruby C Extensions using a Rakefile (ie `gemspec.extensions = ["ext/foo/Rakefile"]`) instead of the standard `extconf.rb` method? This might allow me to optionally build C extensions, and fail gracefully if there's no C compiler, no headers, no libruby, etc.
Ah yes I remember now. The bulk of the C extension building logic is in RubyGems itself. RubyGems will execute extconf.rb, then try to run the resulting Makefile, or error if none was generated.
Fun fact: RubyGems supports `./configure`, `Rakefiles`, and even `CMakeLists.txt` files in `gemspec.extensions`:
https://github.com/ruby/ruby/blob/master/lib/mkmf.rb trying to understand how try_compile causes the extconf.rb file to exit -1 if it fails. mkmf.rb is a tire fire, but amazingly works on any common *nix platform.
Still need to figure out how to make extconf.rb fail gracefully when it cannot build C extensions (ie: no C compiler, ruby-dev/ruby-devel not installed) and print some "Skipping ..." message.
also need to figure out how to optionally build C exts. Say a user installs my library, but doesn't have gcc installed. I'm sure there's a way to make extconf.rb fail silently. Then you'd just have to put `begin/rescue LoadError` around where you load the C exts.
I really like the idea of writing 100% of your code in Ruby, then creating optional C extensions which hook-in and replace "hot" methods with optimized C equivalents. This just requires that you have individual C exts (`extconf.rb` and `myext.c`) for each Class/Module you wish to hook into. Then at the bottom of each myclass.rb/mymod.rb, you'd add:
require 'mylib/myclass_ext` if RUBY_ENGINE == 'ruby'
which only loads the C exts on MRI; JRuby/TruffleRuby/etc can probably optimize the Ruby.
Ported digest-crc to Crystal, which also lead me to making improvements to digest-cr. Fixed a few things, added more CRC algos from pycrc, and did a code spike last night to build C extensions for the pure-Ruby `update` methods and override them when loaded. Appears to work fine when build manually. Now, if only I could get rake-compiler to work... :/
I'm liking #hanami-api. As simple as Sinatra, but with more structure.
Appears someone converted my Spidr library to crystal (https://github.com/watzon/arachnid#examples), added threading and a CLI. Obvious question is how does one keep the logic synced when the Ruby version changes? There's this ruby_crystal_codemod project (https://github.com/DocSpring/ruby_crystal_codemod), but how does one keep the converted code separate from any additional modifications/touch-ups?
I blame Rails mania for shifting everyone's attention away from the system and towards the browser, for better or worse. The browser is cool and all, but there's still a lot of cool things that can be done on the system which are far easier/more performant _outside_ of the browser.
Also like that the Crystal community already wrote bindings for most popular C libraries. Even after Ruby got FFI (ffi gem and fiddle), it took a while for Rubyists to start writing more bindings. There's still a ton of awesome C libraries that we could leverage with Ruby via FFI.
HOLY SH*T! YOU CAN MOVE THE CURSOR AROUND IN MULTI-LINE INPUT, EDIT THE LINES, AND EVEN EDIT PREVIOUS MULTI-LINE STATEMENTS!!!!!!1111
irb has finally become my dream hybrid Ruby REPL/editor. It just missing a way to save/load a session.