We compute the $$\mathcal{N}=2$$
N
=
2
supersymmetric partition function of a gauge theory on a four-dimensional compact toric manifold via equivariant localization. The result is given by a piecewise constant function of the Kähler form with jumps along the walls where the gauge symmetry gets enhanced. The partition function on such manifolds is written as a sum over the residues of a product of partition functions on $$\mathbb {C}^2$$
C
2
. The evaluation of these residues is greatly simplified by using an “abstruse duality” that relates the residues at the poles of the one-loop and instanton parts of the $$\mathbb {C}^2$$
C
2
partition function. As particular cases, our formulae compute the SU(2) and SU(3) equivariant Donaldson invariants of $$\mathbb {P}^2$$
P
2
and $$\mathbb {F}_n$$
F
n
and in the non-equivariant limit reproduce the results obtained via wall-crossing and blow up methods in the SU(2) case. Finally, we show that the U(1) self-dual connections induce an anomalous dependence on the gauge coupling, which turns out to satisfy a $$\mathcal {N}=2$$
N
=
2
analog of the $$\mathcal {N}=4$$
N
=
4
holomorphic anomaly equations.