It is pretty large question.
Not everyone could even produce own electronic components, and producing CPU is much harder. There is list in wiki about semiconductors plants, it isn't full but it shows who could and who not: https://en.wikipedia.org/wiki/List_of_semiconductor_fabrication_plants
(and some of them are fully foreign-controlled).
Producing own military electronics requires heavy investment in research and production, and only few countries care about it. USA, Russia, China and maybe France. Others rather don't care at all (like most of third world countries) or rely on someone (like Europeans with USA/NATO and foreign tech). Actually, only relatively rich places like EU can afford to do something, and most countries in EU don't have a real army, or, like Germany, doesn't know what "security" mean. They don't even have border security, why even talk about electronics?
And yes, it is hard. For example, even today Russia can't produce compact thermal imaging sight for tanks, T-90 has licensed French device made in Belarus. USSR sucked in electronics even with large sums of money spent on military. A Soviet joke: "News report: USSR industry celebrates another victory: our workers created the biggest microchip in the world! This unique product weights 30kg and has 8 carrying handles!".
Military may be ok with bad performance and size for the sake of security and quality. For example, most of military tech in Russia has CPUs with 50-300 MHZ and shielding. But if you want to make generic CPU for public, you can't use this, no one will buy these things. Russia has few CPU designer companies (military institutes, MCST and some new related companies), but only MCST could make something that is suitable for general public: https://en.wikipedia.org/wiki/Elbrus_(computer)
and it often contains foreign components. You also couldn't buy it on market because they don't even try to sell it: no one will buy CPU with performance of early 2000s Pentiums and price of ten new core i7. Only government can force someone to buy it because of security issues. Some of Russian CPUs actually made in Taiwan, like Baikal, and they aren't cheap too. Russian electronics manufacturers can compete on market only in niches like small components production, RFIDs or something, not in CPU or RAM.