Skip to content

Commit

Permalink
Filter out -static option on MacOS X
Browse files Browse the repository at this point in the history
This is to fix gprbuild 24 on Mac OS. The error is

> ld: library not found for -lcrt0.o

The gprbuild call `gcc -static ...` during linking a main, but
MacOS X was never able to do [static linking][1].

The gprbuild reads `-static` option from `*.bexch` file.
The `*.bexch` file is created by `gprbind` by reading
`b__<main>.adb` generated by `gnatbind`.
The `gnatbind` writes `-static` to `b__<main>.adb` for ages,
but gprbuild 22 filtered this option.
The filtering was removed in [the commit][2].

[1]: https://stackoverflow.com/questions/3801011/ld-library-not-found-for-lcrt0-o-on-osx-10-6-with-gcc-clang-static-flag
[2]: AdaCore/gprbuild@48ea3c1
  • Loading branch information
reznikmm committed Mar 13, 2024
1 parent 1af19fd commit d632312
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions specs/gprbuild.anod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ from e3.fs import sync_tree, cp
from e3.anod.helper import Make, text_replace
from e3.anod.spec import Anod
from e3.anod.loader import spec
from e3.diff import patch
import os
from datetime import date

patch_name = "gprbuild-no-static.patch"

class GPRbuild(spec("gh-artifact")):
@property
def version(self):
Expand All @@ -23,6 +26,7 @@ class GPRbuild(spec("gh-artifact")):
url="https://github.com/AdaCore/gprbuild/archive/v%s/%s"
% (self.version, self.tarball),
),
self.LocalSourceBuilder(name=patch_name),
]

@property
Expand All @@ -38,6 +42,7 @@ class GPRbuild(spec("gh-artifact")):
Anod.Source(
name=self.deps["xmlada"].tarball, publish=True, dest="xmlada"
),
Anod.Source(name=patch_name, publish=True, unpack_cmd=cp, dest="patches"),
]
else:
return [
Expand All @@ -47,6 +52,7 @@ class GPRbuild(spec("gh-artifact")):
publish=True,
dest="gprconfig_kb",
),
Anod.Source(name=patch_name, publish=True, unpack_cmd=cp, dest="patches"),
]

@property
Expand Down Expand Up @@ -135,6 +141,13 @@ class GPRbuild(spec("gh-artifact")):

self.update_version()

if self.env.host.os.name == "darwin":
# MacOS X can't execute 'gcc -static', patching gprbuild
patch(
os.path.join(self["SRC_DIR"], "patches", patch_name),
self.build_space.src_dir,
)

if self.bootstrap:
return self.do_bootstrap()

Expand Down
11 changes: 11 additions & 0 deletions specs/patches/gprbuild-no-static.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff -Naur src/gprbuild-link.adb src/gprbuild-link.adb
--- src/gprbuild-link.adb 2023-10-09 21:31:11.000000000 +0300
+++ src/gprbuild-link.adb 2024-03-12 23:46:51.766005336 +0200
@@ -1880,6 +1880,7 @@
when Resulting_Options =>
if not Apply_Bindfile_Option_Substitution
(Line (1 .. Last))
+ and then Line (1 .. Last) /= "-static"
then
Binding_Options.Append (Line (1 .. Last));
end if;

0 comments on commit d632312

Please sign in to comment.