Extract function for native image generation. Call it from the two appropriate places. I wanted to do this when we unpack, since it is a single place we could use. But we haven't moved it out of temp and into the KRE folder at that point. Some more refactoring might be needed.