I want to build two separate executables that share 99% of the same code. So I was thinking, OK, I'll put all the code into a single main.rs, and then use some kind of cfg fun to build that file into two slightly different executables. But... it looks like cargo's [[bin]] configuration doesn't provide any way to have different cfg settings for different targets? Am I missing something? Is there some other way to accomplish what I want?
#Can I get cargo to build the same source file twice with different cfg settings?
5 messages · Page 1 of 1 (latest)
This may or may not work depending on what way they're similar, but you could make most of your code dependent on a trait, then implement that trait differently for each exe. Or have a type with a generic argument, and use it with a different type argument for each exe.
yep; this is generally a better plan than cfging because it lets the common code be compiled only once, and there's less room for making mistakes that make it fail to compile in one case
Got the lib.rs + 2 main.rs version working, thanks!