@@ -59,6 +59,7 @@ public class GoBinary extends AbstractBuildRuleWithDeclaredAndExtraDeps
5959 @ AddToRuleKey private final Linker cxxLinker ;
6060 @ AddToRuleKey private final ImmutableList <Arg > linkerArgs ;
6161 @ AddToRuleKey private final ImmutableList <Arg > cxxLinkerArgs ;
62+ @ AddToRuleKey private final GoLinkStep .BuildMode buildMode ;
6263 @ AddToRuleKey private final GoLinkStep .LinkMode linkMode ;
6364 @ AddToRuleKey private final GoPlatform platform ;
6465
@@ -77,6 +78,7 @@ public GoBinary(
7778 GoCompile mainObject ,
7879 Tool linker ,
7980 Linker cxxLinker ,
81+ GoLinkStep .BuildMode buildMode ,
8082 GoLinkStep .LinkMode linkMode ,
8183 ImmutableList <Arg > linkerArgs ,
8284 ImmutableList <Arg > cxxLinkerArgs ,
@@ -93,15 +95,13 @@ public GoBinary(
9395 this .platform = platform ;
9496 this .withDownwardApi = withDownwardApi ;
9597
96- String outputFormat = "%s/" + buildTarget .getShortName ();
97- if (platform .getGoOs () == GoOs .WINDOWS ) {
98- outputFormat = outputFormat + ".exe" ;
99- }
98+ String outputFormat = getOutputFormat (buildTarget , platform , buildMode );
10099 this .output =
101100 BuildTargetPaths .getGenPath (projectFilesystem .getBuckPaths (), buildTarget , outputFormat );
102101
103102 this .linkerArgs = linkerArgs ;
104103 this .linkMode = linkMode ;
104+ this .buildMode = buildMode ;
105105 }
106106
107107 @ Override
@@ -124,12 +124,37 @@ protected RelPath getPathToBinaryDirectory() {
124124 return output .getParent ();
125125 }
126126
127+ private String getOutputFormat (
128+ BuildTarget buildTarget , GoPlatform platform , GoLinkStep .BuildMode buildMode ) {
129+ String outputFormat = "%s/" + buildTarget .getShortName ();
130+
131+ switch (buildMode ) {
132+ case C_SHARED :
133+ if (platform .getGoOs () == GoOs .DARWIN ) {
134+ return outputFormat + ".dylib" ;
135+ }
136+ if (platform .getGoOs () == GoOs .WINDOWS ) {
137+ return outputFormat + ".dll" ;
138+ }
139+ return outputFormat + ".so" ;
140+ case C_ARCHIVE :
141+ return outputFormat + ".a" ;
142+ case EXECUTABLE :
143+ if (platform .getGoOs () == GoOs .WINDOWS ) {
144+ return outputFormat + ".exe" ;
145+ }
146+ }
147+
148+ return outputFormat ;
149+ }
150+
127151 @ Override
128152 public ImmutableList <Step > getBuildSteps (
129153 BuildContext context , BuildableContext buildableContext ) {
130154
131155 buildableContext .recordArtifact (output .getPath ());
132156
157+ ProjectFilesystem filesystem = getProjectFilesystem ();
133158 SourcePathResolverAdapter resolver = context .getSourcePathResolver ();
134159 ImmutableList .Builder <Step > steps = ImmutableList .builder ();
135160
@@ -151,9 +176,7 @@ public ImmutableList<Step> getBuildSteps(
151176 steps .add (
152177 MkdirStep .of (
153178 BuildCellRelativePath .fromCellRelativePath (
154- context .getBuildCellRootPath (),
155- getProjectFilesystem (),
156- outputResourcePath .getParent ())));
179+ context .getBuildCellRootPath (), filesystem , outputResourcePath .getParent ())));
157180 steps .add (
158181 CopyStep .forDirectory (
159182 resolver .getCellUnsafeRelPath (resource ),
@@ -163,9 +186,7 @@ public ImmutableList<Step> getBuildSteps(
163186 steps .add (
164187 MkdirStep .of (
165188 BuildCellRelativePath .fromCellRelativePath (
166- context .getBuildCellRootPath (),
167- getProjectFilesystem (),
168- outputResourcePath .getParent ())));
189+ context .getBuildCellRootPath (), filesystem , outputResourcePath .getParent ())));
169190 steps .add (CopyStep .forFile (resolver .getCellUnsafeRelPath (resource ), outputResourcePath ));
170191 }
171192 }
@@ -212,7 +233,7 @@ public ImmutableList<Step> getBuildSteps(
212233 ImmutableList .of (linkTree .getRoot ()),
213234 platform ,
214235 resolver .getCellUnsafeRelPath (mainObject .getSourcePathToOutput ()).getPath (),
215- GoLinkStep . BuildMode . EXECUTABLE ,
236+ buildMode ,
216237 linkMode ,
217238 output .getPath (),
218239 ProjectFilesystemUtils .relativize (
0 commit comments