Typically you incorporate union representatives onto boards of companies, make the members shareholders etc. You tie incentive structures together.
Even so, I'm a reject your framing to a certain degree. Employees, and by extension labor unions, typically want to see the company they work at succeed. Labor always pays the price, e.g. forgoing wages during a strike.
And even when a deal is struck, employees often put the interest of the company ahead of their own, e.g. trading away already agreed upon wage increases in a labor contract in order to keep the company solvent.
Are there examples of both situations? Of course! I've seen both first hand, but it certainly isn't completely one or the other. Some companies have a good relationship with their unions, others are very antagonistic.
Well, how do you craft corporate rules to prevent companies from extracting value out of their labor without being abusive, under-compensating people, discriminating, valuing nepotism over competence, exposing employees to unreasonable risk, etc? Most people take pride in their work, care about what they do, want to see the company they work for succeed, want to see competence rewarded, hate having to repeatedly clean up other people’s mistakes and will respect a company that treats them well for doing so. The company has leverage and the union has leverage and they work together. If the union has all the leverage and the company has none and the people in charge of the union are greedy jerks, well then that’s a problem. If the workers have no leverage and the people in charge of the company are greedy jerks, that’s also a problem— but it’s a far more common problem because it’s much easier for companies to get leverage than workers.
Look at the case of the boring company having workers spraying caustic chemicals in enclosed spaces with no PPE and laboring in ankle deep water in heavy work boots which abrade skin even when it’s dry. If a company can’t afford to stay in business without treating their workers humanely then they can’t afford to stay in business. But we all know from the rather well known CEO that lack of capital isn’t the problem.