Is it possible (not feasible) to mine bitcoins with Bitcoin Core v0.21.1?
The setgenerate built-in background miner was removed.
There is however still a test-only on-demand miner, which will try to mine N blocks whenever requested by RPC (see generatetoaddress /generatetodescriptor/generateblock RPCs in recent Bitcoin Core versions). It is many times less efficient than even the built-in CPU miner was. Its only purpose is in functional tests (which use the &quot;regtest&quot; network that is permanently at very low difficulty).
The code you see in miner.cpp is additionally used as a backend for the getblocktemplate RPC, which is how pools and external miners communicate with bitcoind. It doesn't actually do any mining (as in hashing) itself, but provides block templates for others to do so, based on transactions in the mempool and the chain's tip block hash.
The -generate option to bitcoin-cli is just a wrapper around the internal generatetoaddress RPC, which is slightly more convenient (it requests an address from the wallet, and then miner to it). It is in theory usable on mainnet, but it obviously won't ever actually find anything (except with extremely small probability).