facebook / facebook/buck2

Conan toolchain does not work with Conan 2, but works with Conan 1.61.0

Open
#469 5 comments 0 reactions 0 assignees View on GitHub
prelude
Dominant language
Rust
Stars
4.4k
Forks
394
PR merge metrics
No merged PRs in 30d

Description

First: the new Conan toolchain works with Conan 1.61.0.

When trying the new Conan toolchain with Conan 2, I've stumbled upon the following problems and their solutions/hacks:

- `conan_init` does not generate the `user_home` directory and does not write something into the trace file, error messages are:

```text
Action failed: toolchains//:conan-init (conan_init)
Required outputs are missing: Action failed to produce outputs: `buck-out/v2/gen/toolchains/213ed1b7ab869379/__conan-init__/user-home`
```
```text
Action failed: toolchains//:conan-init (conan_init)
Required outputs are missing: Action failed to produce outputs: `buck-out/v2/gen/toolchains/213ed1b7ab869379/__conan-init__/trace.log`
```

I could fix (hack around) this by adding a `mkdir` to `prelude/toolchains/conan/conan_init.py` and writing something into the tracefile:

```python
conan_profile(args.conan, args.user_home, args.trace_file)

with open(args.trace_file, "wt", encoding="utf-8") as trace_file:
trace_file.write("HI")

homedir = Path(args.user_home)
homedir.mkdir()
```

- Now `conan_lock` fails. Error message:

```text
Action failed: root//:lock (conan_lock)
Local command returned non-zero exit code 1
Reproduce locally: `env -- "BUCK_SCRATCH_PATH=buck-out/v2/tmp/root/213ed1b7ab869379/__lock__/conan_lock"
/usr/bin/env "P ...... --conanfile ./conanfile.txt --lockfile-out buck-out/v2/gen/root/213ed1b7ab869379/__lock__/conan.lock (run `buck2 log what-failed` to get the full command)`
stdout:
stderr:
ERROR: Error reading 'buck-out/v2/gen/toolchains/213ed1b7ab869379/__conan-profile-macos-arm64__/conan-profile-macos-arm64' profile: ConfigParser: Unrecognized field 'env'
Traceback (most recent call last):
File "./buck-out/v2/gen/prelude/213ed1b7ab869379/toolchains/conan/__conan_lock__/conan_lock.py", line 104, in
main()
```

Conan does not like the `[env]` stanza of the generated profile file `buck-out/v2/gen/toolchains/213ed1b7ab869379/__conan-profile-macos-arm64__/conan-profile-macos-arm64`, as `env` has been deprecated in favour of `buildenv`

```text
[settings]
arch=armv8
os=Macos
build_type=Release
compiler=apple-clang
compiler.version=15
compiler.libcxx=libc++

[env]
CMAKE_FIND_ROOT_PATH=
AR=$PROFILE_DIR/AR
AS=$PROFILE_DIR/AS
NM=$PROFILE_DIR/NM
RANLIB=$PROFILE_DIR/RANLIB
STRIP=$PROFILE_DIR/STRIP
CC=$PROFILE_DIR/CC
CFLAGS=
CXX=$PROFILE_DIR/CXX
CXXFLAGS=
```

So I changed `prelude/toolchains/conan/defs.bzl` to use `[buildenv]` instead of `[env]`:

```python
content.add("")
content.add("[buildenv]")
```

- Now `conan_lock` does not generate something in it's trace file. Error message:

```text
Action failed: root//:lock (conan_lock)
Required outputs are missing: Action failed to produce outputs: `buck-out/v2/gen/root/213ed1b7ab869379/__lock__/trace.log`
```

So, another "HI" in `prelude/toolchains/conan/conan_lock.py`

```python
conan_lock(
args.conan,
args.profile,
args.conanfile,
args.lockfile_out,
args.lockfile,
args.user_home,
args.trace_file,
)

with open(args.trace_file, "wt", encoding="utf-8") as trace_file:
trace_file.write("HI")
```

- Now my Conan generates a lockfile of version `0.5`, but `lock_generate` wants `0.4`:

```text
Action failed: root//:lock-generate (conan_generate)
Local command returned non-zero exit code 1
...
assert data["version"] == "0.4", "Unsupported Conan lockfile version"
```

And that's the end, because the Conan toolchain wants to read the field `graph_lock`, which does not exist any more in newer lock files.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.