This is doable on iOS.
Settings > Do Not Disturb with the following settings:
- Do Not Disturb: On
- Scheduled: Off
- Silence: Always
- Allow Calls From: All Contacts
You'd lose the ability to use Do Not Disturb to silence your phone, say, overnight, but this would do what you're describing.
Personally, I've opted in to T-Mobile's spam block feature. I don't get any robocalls.