Bug 286154 - WITHOUT_CLANG overrides WITH_CLANG_BOOTSTRAP
Summary: WITHOUT_CLANG overrides WITH_CLANG_BOOTSTRAP
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-17 10:57 UTC by Andriy Gapon
Modified: 2025-04-23 19:41 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andriy Gapon freebsd_committer freebsd_triage 2025-04-17 10:57:34 UTC
I observe that a build with WITHOUT_CLANG skips usr.bin/clang/clang directory even when the build detects that cross-tools are required.

E.g., a build with WITHOUT_CLANG outputs this:
--------------------------------------------------------------
 >>> stage 3: cross tools
--------------------------------------------------------------
===> lib/clang (obj,all,install)
===> lib/clang/libllvm (all)
===> lib/clang/libllvm (install)
===> usr.bin/clang (obj,all,install)
===> usr.bin/clang/lld (obj,all,install)

Comparing to a default build, the following lines are missing:
===> usr.bin/clang/clang (all)
===> usr.bin/clang/clang (install) 

I think that the issue is cased by this check in usr.bin/clang/Makefile:
.if ${MK_CLANG} != "no"
SUBDIR+=        clang
.endif

When building cross-tools and MK_CLANG_BOOTSTRAP is yes, MK_CLANG is still no because of WITHOUT_CLANG.

Those lines in usr.bin/clang/Makefile come from commit https://cgit.freebsd.org/src/commit/?id=8e1c989abbd1db4.

Bug 240507 describes a similar problem, but with a different root cause.
The commit in question was made after the bug fix(es), so it broke the configuration in a different way.
https://cgit.freebsd.org/src/commit/?id=8e1c989abbd1db4
Comment 1 Andriy Gapon freebsd_committer freebsd_triage 2025-04-17 11:02:36 UTC
Oh, forgot to mention the important part.
Because usr.bin/clang/clang is skipped, the cross clang is not actually built and is not installed under tmp/ sub-directory for cross-tools.
So, host clang gets used as a result.
Sometimes that works, sometimes it doesn't.

For example, right now it's not possible to build releng/14.2 on a main host with WITHOUT_CLANG.
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2025-04-17 11:03:51 UTC
My local workaround / fix is to add MK_CLANG=${MK_CLANG_BOOTSTRAP} to XMAKE, but I am not sure if that can have any undesired side-effects.
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2025-04-17 19:16:30 UTC
(In reply to Andriy Gapon from comment #2)
Yeah, I think that is a reasonable approach, and it seems to work. I'll run a few tests to see if there are some side effects, but I expect it to be limited.
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-04-18 18:33:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=ea231471d024e93279dc2196d6d5d87e199ad55b

commit ea231471d024e93279dc2196d6d5d87e199ad55b
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-04-18 10:55:36 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-04-18 18:32:12 +0000

    Fix build with WITH_CLANG_BOOTSTRAP and WITHOUT_CLANG

    When WITH_CLANG_BOOTSTRAP and WITHOUT_CLANG are both set, the
    cross-tools stage does not build a cross clang binary. This is because
    the Makefile in usr.bin/clang checks for WITHOUT_CLANG, and skips
    building the binary.

    To fix this, ensure that WITH_CLANG is set for the cross-tools phase
    whenever WITH_CLANG_BOOTSTRAP is set. While here, skip using the
    Makefile in usr.bin/clang, and directly use the Makefile in
    usr.bin/clang/clang instead.

    PR:             286154
    Reported by:    avg
    Reviewed by:    avg, emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D49886

 Makefile.inc1 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-04-23 19:38:31 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=3f68c3e9c138824024d5a588827381ed85d7230c

commit 3f68c3e9c138824024d5a588827381ed85d7230c
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-04-18 10:55:36 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-04-23 19:36:00 +0000

    Fix build with WITH_CLANG_BOOTSTRAP and WITHOUT_CLANG

    When WITH_CLANG_BOOTSTRAP and WITHOUT_CLANG are both set, the
    cross-tools stage does not build a cross clang binary. This is because
    the Makefile in usr.bin/clang checks for WITHOUT_CLANG, and skips
    building the binary.

    To fix this, ensure that WITH_CLANG is set for the cross-tools phase
    whenever WITH_CLANG_BOOTSTRAP is set. While here, skip using the
    Makefile in usr.bin/clang, and directly use the Makefile in
    usr.bin/clang/clang instead.

    PR:             286154
    Reported by:    avg
    Reviewed by:    avg, emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D49886

    (cherry picked from commit ea231471d024e93279dc2196d6d5d87e199ad55b)

 Makefile.inc1 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-04-23 19:39:39 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5195ff613fca40653d263bbada8a335ad864612e

commit 5195ff613fca40653d263bbada8a335ad864612e
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2025-04-18 10:55:36 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2025-04-23 19:37:40 +0000

    Fix build with WITH_CLANG_BOOTSTRAP and WITHOUT_CLANG

    When WITH_CLANG_BOOTSTRAP and WITHOUT_CLANG are both set, the
    cross-tools stage does not build a cross clang binary. This is because
    the Makefile in usr.bin/clang checks for WITHOUT_CLANG, and skips
    building the binary.

    To fix this, ensure that WITH_CLANG is set for the cross-tools phase
    whenever WITH_CLANG_BOOTSTRAP is set. While here, skip using the
    Makefile in usr.bin/clang, and directly use the Makefile in
    usr.bin/clang/clang instead.

    PR:             286154
    Reported by:    avg
    Reviewed by:    avg, emaste
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D49886

    (cherry picked from commit ea231471d024e93279dc2196d6d5d87e199ad55b)

 Makefile.inc1 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)