Skip to content

Commit e6e9ab4

Browse files
committed
use llvm-objcopy
1 parent fd3f510 commit e6e9ab4

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lake/Lake/Build/Module.lean

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,24 @@ public def Module.coExportFacetConfig : ModuleFacetConfig coExportFacet :=
833833
Recursively build the module's object file from its C file produced by `lean`.
834834
This version does not export any Lean symbols.
835835
-/
836-
private def Module.recBuildLeanCToONoExport (self : Module) : FetchM (Job FilePath) := do
836+
private def Module.recBuildOExportToONoExport (self : Module) : FetchM (Job FilePath) := do
837837
let suffix := if (← getIsVerbose) then " (without exports)" else ""
838838
withRegisterJob s!"{self.name}:c.o{suffix}" <| withCurrPackage self.pkg do
839-
-- TODO: add option to pass a target triplet for cross compilation
840-
buildLeanO self.coNoExportFile (← self.c.fetch) self.weakLeancArgs self.leancArgs self.leanIncludeDir?
839+
try
840+
(← self.coExport.fetch).mapM fun path => do
841+
discard <| IO.Process.run {
842+
cmd := "llvm-objcopy"
843+
args := #["--remove-section", ".drectve", path.toString, self.coNoExportFile.toString]
844+
}
845+
return self.coNoExportFile
846+
catch _ =>
847+
-- fallback if we don't have llvm-objcopy
848+
-- TODO: add option to pass a target triplet for cross compilation
849+
buildLeanO self.coNoExportFile (← self.c.fetch) self.weakLeancArgs self.leancArgs self.leanIncludeDir?
841850

842851
/-- The `ModuleFacetConfig` for the builtin `coNoExportFacet`. -/
843852
public def Module.coNoExportFacetConfig : ModuleFacetConfig coNoExportFacet :=
844-
mkFacetJobConfig recBuildLeanCToONoExport
853+
mkFacetJobConfig recBuildOExportToONoExport
845854

846855
/-- The `ModuleFacetConfig` for the builtin `coFacet`. -/
847856
public def Module.coFacetConfig : ModuleFacetConfig coFacet :=

0 commit comments

Comments
 (0)