Just three days after his inauguration, the president courted labor by inviting the heads of several building trades unions to the Oval Office. Afterward, they sounded almost giddy, with the president of the laborers’ union issuing a news release headlined, “It is Finally Beginning to Feel Like a New Day for America’s Working Class.”

Sean McGarvey, president of North America’s Building Trades Unions, came away applauding Mr. Trump’s plans for the Keystone Pipeline and other projects, which could mean more than 100,000 new jobs. “So far so good — our concern is basically the economic trajectory of our membership,” Mr. McGarvey said. (Though when President Trump spoke last week to the construction unions’ legislative conference, some union officials — unhappy about his push to repeal Obamacare and his rolling back of some worker safety regulations — booed him and held up signs saying, “Resist.”)

Although labor unions have declined in size and might — just 10.7 percent of American workers belong to unions, down from 30 percent under President John F. Kennedy — they still pack plenty of political punch. Many labor leaders were mortified that Hillary Clinton narrowly lost in three longtime union strongholds, Michigan, Pennsylvania and Wisconsin; they say that if she and labor had campaigned a bit smarter in those states, she could have won them, and the White House. One reason she lost Wisconsin is that union rolls there have plummeted — from 15 percent of all workers in 2009 to 8 percent today. A big reason: Gov. Scott Walker moved aggressively to shrink Wisconsin’s public-sector unions.

Mr. Trump has focused his attentions on private-sector unions and workers, like miners in Kentucky and steelworkers in Pennsylvania. “Trump is doing what both Nixon and Reagan tried to do: pick out a few of the likeliest unions and see if you can make nice with them,” said Joseph McCartin, a labor historian at Georgetown University. He noted another similarity — while the Reagan administration had numerous officials interested in working with unions, it, like the Trump administration, also had fiercely anti-labor officials eager to weaken unions.

The nation’s unions are divided into three camps regarding Mr. Trump.

The construction trades are the most pro-Trump. Many liberals have criticized Mr. McGarvey’s enthusiastic words for the president, but he said it’s smart to work with politicians. “We’re working on creating a building trades majority, Democratic and Republican, whether state or national,” he said. “We never want to be in a position where losing an election changes the economic trajectory of our membership.”