Computer hardware does not degrade faster when it is being used, assuming adequate cooling. Generally, what kills electronics is heat, and heat can be mitigated by sufficient cooling; in modern personal computers, this typically means active cooling by forced air, but other possibilities (including water cooling and, in low-powered systems, strictly passive/convective cooling) exist. Which malfunctions cause old computers to slow down and crash? and Is it possible for a router to “go bad” with time? touch on this.
There is one main exception to this, and that is flash-based storage such as that used in SSDs, which has a limited number of write cycles before each flash cell wears out. However, modern SSDs go to great lengths to mitigate this, and despite what people might tell you selected for the intended workload in most client and server workloads are plenty durable enough, even more so from a flash wear perspective. This includes compiling software, which while it does tend to create a large number of files (involving lots of small writes) is also heavily cacheable by the system and thus doesn't necessarily imply so many writes to stable storage. As Serge pointed out, as an alternative you can consider running the build on a tmpfs type file system, which normally uses RAM for storage but will resort to swap space if sufficient RAM is unavailable. That is also likely to speed up compilation, since particularly for large projects compilation is more likely to be IOPS constrained than I/O throughput or CPU constrained; and even if it is CPU constrained, the higher IOPS attainable through using RAM to store source code files will not make the situation significantly worse.
The main electronics killer aside from heat is voltage impurities, which is a factor of the power supply and largely unrelated to what tasks you perform on the computer. With a properly rated power supply (which is mostly a concern if you build a computer yourself from parts) and aside from input AC impurities (which will affect any electronics), this for all intents and purposes won't be an issue.