It’s relatively trivial (but more expensive than getting it straight from the ground) to synthesize oil from atmospheric components + energy. Some countries have done it at large scales during wartime.
This is the issue. A lot of hydocarbons can still be produced without extracting them from rocks miles under the ground, poisoning the water supply, or any of the externalities of runaway global warming.
The trick is leveraging insanely cheap solar electricity to do everything else.
Which countries would that be? Capturing CO2 from the atmosphere in order to have a source of carbon is, to this day, a technology in the prototype stage.
If you're thinking of Germany during WWII, or South Africa during apartheid, they produced synthetic liquid fuels from coal. That was technology that worked, though it was very expensive. And of course CO2 emissions were much higher than using petroleum.
The chemistry isn't that hard to produce oil from basically nothing of value, but the energy costs aren't trivial, and that means we don't need a 1:1 energy replacement from fossil fuel sources to solar panels, we need more like a 10x increase in global energy production to replace fossil fuels with solar for example.
The only really feasible way to produce that much electricity renewably by this point in time or even within the next 20+ years has been nuclear energy, which the world largely turned their backs on the last few decades and left us in an even bigger hole to fill.