What would induce a software developer to quit a good job in Silicon Valley and trade California's sunshine for Toronto's wintry skies?

For Vikram Rangnekar, born in India and educated in the U.S., the triggers were the restrictions placed on immigrant tech workers holding an H-1B visa (starting companies or taking long holidays is discouraged) and what looked like a 20-year wait to get the green card he needed to settle down.

Rising anti-immigrant sentiment under President Donald Trump's administration did not help. Two years later, he thinks he made the right choice. "I didn't want to spend the best years of my life on a restrictive visa."

People like Rangnekar are part of an exodus of tech workers from Silicon Valley. Pushed out by the cost of living as well as by a less welcoming U.S. government, they are being reeled in by countries such as Canada, where tech vacancies are forecast to reach 200,000 by 2020. Canada is gambling that by the time the U.S. wakes up to the cost of discouraging immigrants, its tech sector will have secured some of the best talent.

The starting point is pretty promising. Toronto already has expertise in artificial intelligence and an array of promising firms such as Wattpad, a storytelling platform with 65 million readers. The city added more tech jobs in 2017 than the San Francisco Bay Area, Seattle and Washington, D.C., combined.

Ottawa is home to Spotify, a publicly traded e-commerce platform valued at $14 billion. Montreal has Element AI, a lab co-founded by Yoshua Bengio, and labs opened by Facebook and Samsung.

Yet Canada is in the third tier of destinations globally, says a study on venture-capital investment, "The Rise of the Global Start-Up City," co-authored by Richard Florida, an urbanologist.

To move up, the government has tweaked both its permanent and temporary immigrant programs. Applicants for permanent residence get extra points for tech skills. Temporary visa holders' spouses are allowed to work.

"I can clearly see the reason why people are shifting to us," says Allen Lau, the chief executive of Wattpad. "The U.S. is becoming less friendly."