Why Do Compiling the Same Code on Different OS Yield Different Hashes?

I compiled the same code on my MacBook (macOS) and a CI server (Ubuntu), both using the same version of DFX, but the resulting WebAssembly (WASM) hash is different, even with the simplest code I tested.

import Text "mo:base/Text";

actor {
    public func say(name: Text) : async Text {
        "Hello " # name # "!"
    }
};

What could be causing this discrepancy?

I remember looking at this a while ago and I think the differences are actually due to the runtime system which is compiled with Rust but produces slightly different binaries on mac0S and Ubuntu.
The compiler generated code, that is statically linked to the runtime system, should be the same.
A fix might be to produce the RTS on linux only and re-use the same rts for both mac0S and Ubuntu moc compilers, but I’m open to suggestions.

Related moc issue: fix: use symbolic mangling in rts to avoid platform differences by crusso · Pull Request #3220 · dfinity/motoko · GitHub