Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolutify CXX as well as CC #969

Merged
merged 2 commits into from
Nov 1, 2021

Conversation

illicitonion
Copy link
Collaborator

Also add the --sysroot flag if needed

This is needed for in-tree CXX values because we chdir before execing the build script binary.

Fixes #950

@hlopko
Copy link
Member

hlopko commented Oct 13, 2021

Can you think of a test?

@illicitonion illicitonion force-pushed the absolutify-cxx branch 3 times, most recently from f4fd419 to 9586655 Compare October 13, 2021 15:02
@illicitonion
Copy link
Collaborator Author

@hlopko Added one - WDYT?

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

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

One comment from me but otherwise looks good 😄

@@ -258,15 +259,6 @@ fn get_target_env_vars<P: AsRef<Path>>(rustc: &P) -> Result<BTreeMap<String, Str
.collect())
}

fn absolutify(root: &Path, maybe_relative: OsString) -> OsString {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a potential source of regressions. Maybe do this in a separate PR?

@ikalchev
Copy link
Contributor

Hi all,

I may be wrong as I have little experience with bazel and less so with rules_rust, so bear with me.

I think the compiler_path needs to be transformed to a string before concatenating the sysroot options. As it is, the compiler_path is a PathBuf, so when we push the sysroot we get, e.g. /path/to/gcc/ --sysroot=//path/to/sysroot (note the trailing / after gcc).

Also, for some reason the cc_toolchain flags are not passed. We have a cc_toolchain that sets -D_GLIBCXX_USE_CXX11_ABI=0 and when we try to link a rust_library that depends on a cargo_build_script with a cc_binary, we get an e.g. undefined reference to some_fn(std::basic_string...), because the cc_binary tries to pass a std::basic_string but the cargo_build_script output binary expects a std::__cxx11::basic_string.

I managed to fix sysroot problem by using String before adding the sysroot options. Without this, the command expands to just the sysroot path. I haven't found a fix for the second issue.

I can test any potential fixes so let me know if I can help.

Best,
Ivan

@illicitonion
Copy link
Collaborator Author

I think the compiler_path needs to be transformed to a string before concatenating the sysroot options. As it is, the compiler_path is a PathBuf, so when we push the sysroot we get, e.g. /path/to/gcc/ --sysroot=//path/to/sysroot (note the trailing / after gcc).

Yes indeed, this was a good catch! Fortunately @scentini noticed this and fixed it in #976 :)

Also, for some reason the cc_toolchain flags are not passed. We have a cc_toolchain that sets -D_GLIBCXX_USE_CXX11_ABI=0 and when we try to link a rust_library that depends on a cargo_build_script with a cc_binary, we get an e.g. undefined reference to some_fn(std::basic_string...), because the cc_binary tries to pass a std::basic_string but the cargo_build_script output binary expects a std::__cxx11::basic_string.

This is definitely an issue too, but a separate one - if you're able to put together a PR to fix it that would be wonderful! I imagine we should be using CFLAGS/CXXFLAGS/LDFLAGS env vars to pass these, rather than concatenating them into the CC/CXX env vars, but I'm very willing to be convinced otherwise by someone who knows what they're talking about :)

FWIW there's a demo of getting these flags from the toolchain in a rule here - a PR that basically did this, in cargo_build_script, to set the appropriate env vars, would be great! (Though exactly how we'd go about testing it, I'm not quite sure...)

@illicitonion illicitonion merged commit b3e26e0 into bazelbuild:main Nov 1, 2021
@illicitonion illicitonion deleted the absolutify-cxx branch November 1, 2021 10:04
@ikalchev
Copy link
Contributor

ikalchev commented Nov 1, 2021

Sound good, thanks for the pointers! Let me see if I can draft something.

@ikalchev
Copy link
Contributor

ikalchev commented Nov 8, 2021

@illicitonion Any chance we can get a new create_universe release? When using the latest commit, there seems to be an API change that leads to:

Error: Failed to parse config file "crates.resolver_config.json"

Caused by:
unknown field `additional_registries`, expected one of `repository_name`, `packages`, `cargo_toml_files`, `overrides`, `crate_registry_template`, `target_triples`, `cargo`, `rust_rules_workspace_name`, `index_url` at line 2 column 28

@illicitonion
Copy link
Collaborator Author

@ikalchev We're not currently doing releases - how are you pulling the binary in and running your build?

@ikalchev
Copy link
Contributor

ikalchev commented Nov 8, 2021

We set the rules_rust repo to some CLN above this PR, define the DEFAULT_URL_TEMPLATE for the resolver to point to "https://github.com/bazelbuild/rules_rust/releases/download/crate_universe-13/crate_universe_resolver-{host_triple}{extension}" and then use the create_universe as:

crate_universe(
    name = "crates",
    cargo_toml_files = [
        ...
    ],
    packages = [
        ...
    ],
    resolver_download_url_template = DEFAULT_URL_TEMPLATE,
    resolver_sha256s = DEFAULT_SHA256_CHECKSUMS,
    supported_targets = [
        "x86_64-unknown-linux-gnu",
    ],
)

I guess we can build the resolver from source ourselves and host it somewhere but was hoping for an official release.

@illicitonion
Copy link
Collaborator Author

This reminds me, I think we reached rough consensus on releases, but haven't done any yet... I'll poke #415 :)

@ikalchev
Copy link
Contributor

ikalchev commented Nov 9, 2021

@illicitonion Is the guidance then to build the resolver from source?

@illicitonion
Copy link
Collaborator Author

@illicitonion Is the guidance then to build the resolver from source?

cargo build --release --manifest-path crate_universe/Cargo.toml should do the job!

shikhar pushed a commit to shikhar/rules_rust that referenced this pull request Nov 26, 2021
shikhar pushed a commit to shikhar/rules_rust that referenced this pull request Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Failed to find tool. Is cc_wrapper.sh installed?"
4 participants