I remember seeing it remarked that the invention of gunpowder was so random that a writer could have a plausible excuse for it to happen at any time, so that got me wondering, what's the soonest that it could be combined with other technologies to make effective weapons? As far as I can tell, Early Modern muskets were mostly made from wrought iron, which opens the door for a lot of ancient civilizations, but I'm not sure about the gears, springs, and screws that go into a flintlock or snap matchlock, and what kind of mechanical engineering the ancient Romans or Egyptians or Chinese had.