How to get the most, 38, cantrips (on the side of not-viable): (You only miss out on 6 and a blaster doesn't need Shillelagh, Green-Flame Blade, Booming Blade, or Lightning Lure. The other two I didn't include are Spare the Dying and Encode Thoughts, but you can substitute any of these 6 where you like)
The Build
Classes:
You may want to shuffle cantrips with shared lists around to land your attack spells on your primary casting ability or get the cantrips that I didn't choose, for this list I've assume Charisma.
- Warlock 4 (The Celestial, Pact of the Tome): Light, Sacred Flame, Eldritch Blast, Magic Stone, Toll the Dead, 3 cantrips in your Book of Shadows✝ +8
- Sorcerer 1: Acid Splash, Chill Touch, Ray of Frost, Shocking Grasp +4
- Cleric 1 (Arcana Domain): Word of Radiance, Guidance, Resistance, Sword Burst, Poison Spray +5
- Bard 10 (College of Lore): Thunderclap, Blade Ward, Friends, Mending, Primal Savagery, Thorn Whip, Mage Hand, Message +8
- Druid 2 (Circle of the Land): Infestation, Control Flames, Druidcraft +3
- Wizard 2 (School of Illusion): Minor Illusion, Mold Earth, Gust, Create Bonfire +4
✝ See Races for which ones to choose.
Feats:
- Magic Initate: Two cantrips✝ +2
- Spell Sniper: One cantrip✝ +1
✝See Races for which ones to choose.
Races:
High elf gives you one wizard cantrip (choose Fire Bolt) and sets your primary casting ability to Intelligence (this is where your 1 ASI should go to reach 18 Intelligence).
Tiefling gives you Thaumaturgy and sets your primary casting ability to Charisma or Intelligence (choose either, this determines whether you choose Wizard or Bard/Sorcerer for your feats).
Half-Elf (Variant) gives you the option to get the High-Elf Cantrip feature (choose Fire Bolt if going Intelligence or Dancing Lights if going Charisma or Wisdom) and sets your primary casting ability to Intelligence, Wisdom, or Charisma (choose any, this determines your choices for your feats).
The Devil's Tongue variant Tiefling gives you Vicious Mockery and sets your primary casting ability to Charisma or Intelligence (choose either, this determines whether you choose Wizard or Sorcerer for your feats).
Drow gives you Dancing Lights and sets your primary casting ability to Charisma.
Fire genasi gives you Produce Flame and sets your primary casting ability to Intelligence.
Water genasi gives you Shape Water and sets your primary casting ability to Wisdom.
Yuan-Ti Pureblood gives you Poison Spray and sets your primary casting ability to Charisma or Intelligence (choose either, this determines whether you choose Wizard or Bard/Sorcerer for your feats).
- Choose Wizard or Bard for Magic Initiate to get Dancing Lights and
Fire Bolt or Vicious Mockery
- Choose Wizard or Sorcerer for Spell Sniper to get Frostbite
- Your Book of Shadows should contain Thaumaturgy, Produce Flame, and
whichever you didn't get from Magic Initiate
- Replace Poison Spray with Shape Water in the Wizard section.
Magic Items:
While you can't know the other two possible cantrips, you can gain access to them through attuning to the following magic items:
- Staff of the Magi: This gets you Mage Hand so you can choose a different spell for Magical Secrets. Since this also gets you light, you could choose The Undying patron instead of The Celestial for Spare the Dying instead of Sacred Flame. +1
- Ring of Shooting Stars (for non-Drow): This one is more limited as you can only use Dancing Lights in dim light or darkness with it but its lets you choose Prestidigitation or True Strike instead of Dancing Lights in all the places you would usually choose Dancing Lights under Race. +1 ish
Viability
To make this build semi-viable ,you would have to learn the feats from a special trainer instead of from ASI (DMG 231).
This would allow your primary casting ability to be brought to 20 and 1 secondary ability to be increased once.