The Sun and other main-sequence stars are produced by the initial gravitational collapse of a molecular cloud.
When considering the formation of stars such as the Sun and other main-sequence stars, it is through the initial gravitational collapse of a molecular cloud that they are produced.