@@ -833,15 +833,24 @@ public def Module.coExportFacetConfig : ModuleFacetConfig coExportFacet :=
833833Recursively build the module's object file from its C file produced by `lean`.
834834This 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`. -/
843852public def Module.coNoExportFacetConfig : ModuleFacetConfig coNoExportFacet :=
844- mkFacetJobConfig recBuildLeanCToONoExport
853+ mkFacetJobConfig recBuildOExportToONoExport
845854
846855/-- The `ModuleFacetConfig` for the builtin `coFacet`. -/
847856public def Module.coFacetConfig : ModuleFacetConfig coFacet :=
0 commit comments