The United States appears on the brink of ending a four-decade ban on most exports of crude oil, which would end a years-long fight brought about by a boom in domestic shale output that contributed to a supply glut and depressed prices.

The measure is part of a sprawling deal wrapped up by congressional leaders late on Tuesday to keep the US government open through September. The $1.15 trillion spending bill, negotiated in secret talks over the last two weeks, would be difficult for President Barack Obama to veto despite his opposition to ending the oil export ban.

In a partial victory to Obama and other Democrats, the spending bill also includes granting tax incentives to boost wind and solar development, according to lawmakers involved in the talks. Shares of solar companies rose sharply.

Republican and Democratic lawmakers will meet separately on Wednesday to discuss the bill and hope to vote on it as soon as Friday.

Allowing oil exports would be a win for the US oil industry and Republicans, who had argued the ban was a relic of the 1970s Arab oil embargo.

Exploration and production companies, many saddled with billions in debt and struggling to avoid bankruptcy after a 60% slide in oil prices forced them to halt most new drilling, had viewed exports as a lifeline of sorts.

But with US output now falling as oil prices slump to seven-year lows, traders say foreign buyers may not materialize in a glutted global market.

The S&P Energy Index .SPNY was down over 1% in early afternoon trading on Wednesday.

Some Democrats in the Senate say lifting the ban would put oil refining jobs at risk and that more drilling would harm the environment, though Democratic Sen. Heidi Heitkamp, from the No. 2 oil state North Dakota, has supported its repeal.

The drop in oil prices, now below $40 a barrel, has helped ease worries about higher gasoline prices for consumers.

Producers say eliminating the ban would help revive a US drilling boom by closing the years-long gap between cheaper domestic crude prices and higher global rates. The move would also give US allies alternatives to Russia and the Organization of Petroleum Exporting Countries for their supplies.

"Lifting the oil export ban is very important to our industry to enable them to compete on a global basis," said Senator John Hoeven. The Republican from oil-producing North Dakota has pressured Congress to axe the trade restriction.

Chief executive officers of US oil producers, from integrated global majors Exxon Mobil Corp to frackers like Continental Resources Inc, had urged the ban be lifted.

Gregory Hill, President of US oil independent Hess Corp, said this month that ending the prohibition would boost domestic crude prices by about $3 a barrel, or about 8%, from around $36.

Refiners have been divided on the issue, as exports of crude would increase their costs after a bounty of cheap domestic oil brought several years of surging profits.

Four US independent refiners, three of which operate on the East Coast, have opposed exporting domestic crude. Their so-called CRUDE Coalition says lifting the ban will lead to higher pump prices when once-landlocked domestic crude commands higher prices in global markets.

PBF Energy Inc, Philadelphia Energy Solutions LLC, Alon USA Energy Inc and Delta Air Lines unit Monroe Energy also say the ban protects national security and supports economic growth by keeping energy prices low for manufacturers. Other refiners, including Valero Energy Corp, Marathon Petroleum Corp and Phillips 66, have expressed support for free markets or said they would not oppose the ban's repeal.

Some pipeline and terminal companies have already started adding infrastructure along the US Gulf Coast to handle potential crude exports, augmenting systems geared toward imports.

Republicans made lifting the ban a priority and swapped it for measures Democrats wanted to reduce carbon emissions and protect the environment.

For the solar industry, the deal marks its second big recent victory since a global agreement to curb carbon emissions and encourage investment in renewable energy, reached in Paris on Saturday. SolarCity Corp, First Solar Inc, Abengoa SA, SunEdison Inc and Sunrun, as well as the industry's trade group, have spent more than $2 million lobbying Congress this year, according to public records compiled by the Center for Responsive Politics.

They pushed hard this month to safeguard the Investment Tax Credit for the industry, which they say has underpinned an annual growth rate of 76% in solar installations over the last decade.

SolarCity shares jumped 26%, First Solar rose 9%, SunEdison was up 19% and Sunrun gained 21%.

The bill, posted early on Wednesday morning, allows the US president to stop oil exports for one year if he or she declares a national emergency, or if the administration decides the exports are causing a domestic oil shortage or raising prices.