The game was reverse engineered as 1-1 compilable to the original rom.
[1]:https://github.com/n64decomp/sm64
Fun fact: The people who did this moved on to Zelda 64 Ocarina of time and recently completed that project as well
There are ongoing projects by other people for Mario Kart 64, Goldeneye, Perfect-Dark, Banjo-Kazooie and others although I think the next target for completion may probably be either Majora's Mask or The Minish Cap.
If you're bored, his write up on the "Challenge 7 Bug" is great read: https://gitlab.com/ryandwyer/perfect-dark/-/blob/master/docs...
An updated version that was released later
Nintendo did (supposedly) use an emulator for the N64 games in Nintendo Online (for the Switch); so it's possible that they don't have the source (or maybe it had enough machine-specific code that doing a source port would be more effort).
Of course, if they can re-sell it as a subscription service they probably would want to avoid releasing the source anyway…