When being referred to in the manner described, it's being used as a proxy for race, so that was indeed racist.
To try and win an election specifically by rallying people against a domestic populous as their enemy is an awful hitler-esque thing to do. Isn't that literally the same recipe?