Skip to content

Conversation

@yanok
Copy link
Contributor

@yanok yanok commented Dec 9, 2025

I'm still not fully convinced this is the right approach, but it simplifies some things and hopefully provides better compatibility with different cc toolchains.

I've tested it on Mac/ARM64 and Linux/AMD64.

Looking forward to feedback.

@yanok
Copy link
Contributor Author

yanok commented Dec 9, 2025

Ok, windows fails since I didn't get the library name right... Is it phobos2.lib, not libphobos2.lib?

I don't yet understand why Linux fails though... Works for me just fine.

@dcarp
Copy link
Collaborator

dcarp commented Dec 10, 2025

I don't yet understand why Linux fails though... Works for me just fine.

I think you are using a llvm C toolchain on your machine, but github runners have gcc installed.

@yanok
Copy link
Contributor Author

yanok commented Dec 10, 2025

I don't yet understand why Linux fails though... Works for me just fine.

I think you are using a llvm C toolchain on your machine, but github runners have gcc installed.

I've tried with --action_env=CC=gcc and it still works (I've also verified that it does respect the CC environment variable). The error is weird: it complains about missing symbols, but those are in libphobos2...

I will try using a container with exact versions GHA is using later.

@dcarp
Copy link
Collaborator

dcarp commented Dec 10, 2025

I don't think that action_env will help here. The detected local cc_toolchain will still be llvm and thus it will use the llvm linker (lld).

yanok and others added 6 commits December 11, 2025 16:50
This is required to use `cc_common.link`
With 0.2.0 I'm getting the error about the missing bzl file.
To properly integrate PIC support with rules_cc, we need to
create both PIC/non-PIC versions of every object, like rules_cc does,
and pass both to
cc_common.create_library_to_link/create_compilation_outputs
This is the main change. Instead of linking with D compiler, call
`cc_common.link` for better portability.

This requires some changes, mainly we don't collect libraries anymore,
instead we build `LinkingContext` for rules_cc.

This simplifies handling of C dependencies, but add a bit of wrapping
around D libraries.
Also we are passing the flags directly to CC now, so we need to drop -L.
@yanok yanok force-pushed the yanok/link-with-cc-common-windows-macos-wip branch from cf9c28e to 7e99dde Compare December 11, 2025 21:18
@yanok
Copy link
Contributor Author

yanok commented Dec 11, 2025

I don't think that action_env will help here. The detected local cc_toolchain will still be llvm and thus it will use the llvm linker (lld).

Yes, you are right! Even though setting CC=gcc via action_env does make it link with gcc as a driver, it still passes -fuse-ld=lld, so lld is used.

It turned out to be about the order of libs to link, apparently lld is more permissive here.

Now it still fails on windows, but now it can find libc functions, like snprintf... I know nothing about Windows and don't have a place to experiment, so I can't fix it.

@yanok yanok requested a review from dcarp December 11, 2025 21:40
Copy link
Collaborator

@dcarp dcarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It looks good! I added two comments.

@yanok yanok force-pushed the yanok/link-with-cc-common-windows-macos-wip branch from 87d8228 to be400ae Compare December 14, 2025 12:49
@yanok yanok requested a review from dcarp December 14, 2025 12:54
@dcarp dcarp merged commit de16982 into bazel-contrib:main Dec 14, 2025
23 checks passed
@dcarp dcarp mentioned this pull request Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants