We've been doing that "one codebase library carved out at compile time to fit the platform" thing for decades on Univac-then-Sperry-then-Unisys 1100/2200 family mainframes.
We use a scripting language called SSG and the sensible use a front-end/database called COMUS to manage it all.
What, you thought mainframe OS's were hand written for site specific platforms?
What, you thought that mainframe utilities were one-size-fits-all (nearly) like they aren't on Unix?
Unisys OS2200 is also Open Source, or was when I last worked with it, and had been for most of it's decades old life.
What, you thought you invented Open Source *and* sex?