It comes from when the star goes supernova. The star collapses very rapidly sending temperatures and pressures to truly astronomic levels. In these moments all the things heavier than iron get synthesized. Indeed it is that rapid nearly all-at-once fusion that provides the energy for the supernova explosion (sufficient to outshine the entire galaxy it is in).
See the Nucleosynthesis article linked above. In particular, see the nice color-coded periodic table. All of the natural occurring elements are … (big surprise) naturally occurring, inside stars or when they explode. Heavier elements take bigger events.
(So, we’re not just stardust. We’re also supernova dust! At least, part of us is.)