Skip to content

Conversation

@troibe
Copy link
Contributor

@troibe troibe commented Feb 26, 2025

I could not find a way to read out the host architecture in lowrisc_rv32imcb_repos.
Using load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
at that stage leads to cycles in the workspace file.

Instead I now download both the ARM and X86 toolchains.
Next I register both and finally I let Bazel decide which one to use
as part of the automatic toolchain resolution.

@troibe troibe requested a review from luismarques February 26, 2025 22:55
@troibe
Copy link
Contributor Author

troibe commented Feb 26, 2025

This relates to lowRISC/lowrisc-toolchains#85.
Once there is a new release of the toolchain we can adjust the URL.

@nbdd0121
Copy link

We're no longer using this repo. OT now uses rules_cc and in-repo rules instead

@jwnrt
Copy link
Contributor

jwnrt commented Feb 27, 2025

CRT is still used by the earlgrey_1.0.0 branch I think, is this what you’re using?

I haven’t done anything per-platform like this before so I’m no help, sorry.

@troibe
Copy link
Contributor Author

troibe commented Feb 27, 2025

Yes @jwnrt I was trying these changes for the earlgrey branches.
Later I'll have a look at the in-repo rules on master as well.

@troibe
Copy link
Contributor Author

troibe commented Feb 27, 2025

This should be ready for review now.
It now relies on Bazel's automatic toolchain resolution.
Only downside is that both toolchains have to be downloaded before the toolchain resolution occurs.

Before merging we should have this point to a new release of the lowrisc toolchains
now that lowRISC/lowrisc-toolchains#85 is merged.

@nbdd0121
Copy link

I think this should be using Bazel toolchains and constraints instead of using a driver shell script with uname. But I don't know how to do this properly @pamaury

@pamaury
Copy link
Collaborator

pamaury commented Feb 27, 2025

I think this should be using Bazel toolchains and constraints instead of using a driver shell script with uname. But I don't know how to do this properly @pamaury

I suspect there is a better way of doing this to avoid downloading both toolchains but I need to look at the bazel documentation.

@pamaury
Copy link
Collaborator

pamaury commented Feb 28, 2025

After a bit of searching, I suspect the proper way of doing this is to change compiler.bzl so that exec_compatible_with is set to the right value. Currently it's hardcoded for x86_64:

    native.toolchain(
        name = "cc_toolchain_" + name,
        exec_compatible_with = [
            "@platforms//cpu:x86_64",
        ],
        target_compatible_with = constraints,
        toolchain = ":" + name,
        toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
    )

Therefore I would suggest to try to add an argument to setup which is the host architecture and use that to replace the hardcoded exec_compatible_with.

@troibe
Copy link
Contributor Author

troibe commented Feb 28, 2025

Ok great! Thanks for the feedback @pamaury.
Then that matches the route I took in the code of this PR.

As I just realized my concern regarding downloading both toolchains was unfounded.
Bazel seems to resolve the http_archive targets and and will only download the target for the host platform.
Sorry about the confusion...I didn't realize Bazel is that "smart".

@troibe
Copy link
Contributor Author

troibe commented Feb 28, 2025

@nbdd0121 Instead of using one driver shell script with uname -m I could instead try passing in the host architecture information from Bazel (let me look into that...).
Alternatively I could just create two separate driver.sh files for each host architecture and have Bazel decide between them.

@pamaury
Copy link
Collaborator

pamaury commented Feb 28, 2025

@nbdd0121 Instead of using one driver shell script with uname -m I could instead try passing in the host architecture information from Bazel (let me look into that...). Alternatively I could just create two separate driver.sh files for each host architecture and have Bazel decide between them.

I think using uname -m is a reasonable solution for now. There certainly are better solutions but since we don't use the crt repository upstream anymore, I don't think it's worth spend too much time on it.

Copy link
Collaborator

@pamaury pamaury left a comment

Choose a reason for hiding this comment

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

I can't test it but the code looks good to me.

@jwnrt
Copy link
Contributor

jwnrt commented Mar 3, 2025

I have cut a release of the toolchain, feel free to update the URL

https://github.com/lowRISC/lowrisc-toolchains/releases/tag/20250303-1

This registers both the x86 and the aarch64 toolchain.
Bazel then decides which one to use as part of the automatic toolchain resolution.
@nbdd0121
Copy link

nbdd0121 commented Mar 3, 2025

Ok great! Thanks for the feedback @pamaury. Then that matches the route I took in the code of this PR.

As I just realized my concern regarding downloading both toolchains was unfounded. Bazel seems to resolve the http_archive targets and and will only download the target for the host platform. Sorry about the confusion...I didn't realize Bazel is that "smart".

👍 Using of uname is fine by me if only 1 copy of toolchain is downloaded.

@jwnrt jwnrt merged commit 1fc9f9d into lowRISC:main Mar 3, 2025
1 check passed
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.

4 participants