aws / aws/aws-sdk-cpp

Generate pkg-config contains spurious cflags

Aperta
#2,673 6 commenti 1 reazione 0 assegnatari Vedi su GitHub
Cmake feature-request p3
Lingua principale
C++
Stelle
2.2k
Fork
1.2k
Merge medio
4g 11h
PR unite (30g)
13

Descrizione

### Describe the bug

#### Context

`pkg-config` is a Unix tool that allows easy retrieval of compiler and linker flags of dependencies. It relies on `.pc` files installed in a standard location, and a utility to query flags from your build system.

#### Issue

The currently generated pkg-config file contains spurious compiler and linker flags that are not meant for users of the library, but rather are a dump of what was used to build the SDK itself.

### Expected Behavior

I would expect the following compiler flags for e.g. an S3-only build:
```
$ pkg-config --cflags aws-cpp-sdk-s3
-I/include
```

And the following linker flags:
```
$ pkg-config --libs aws-cpp-sdk-s3
-L/lib -laws-cpp-sdk-s3 -laws-cpp-sdk-core
```

### Current Behavior

It seems the current build toolchain just dumps its **own** build flags in the pkg-config file, instead of the build flags that **users** of the SDK should use, which means we end up with:
1) Build-relative paths, which are useless (if not straight up dangerous) for users of the library
2) Internal compiler flags used to build the AWS C++ SDK itself, which incorrectly leak to the users of the library

More precisly, after an S3-only build, here is the output of pkg-config:
```
$ pkg-config --cflags aws-cpp-sdk-s3
-fno-exceptions -std=c++11 -fno-exceptions -std=c++11 -Iinclude
```
- `-fno-exceptions` is an implementation choice of the AWS C++ SDK which should not leak to the users of the SDK. Linking exception-aware code with the SDK should be allowed (just as linking with C code from C++ is allowed).
- `-std=c++11` is also an implementation choice of the SDK that should not leak to its users. Using the SDK from a C++ 14 / 17 / 20 / 23 codebase should be supported.
- `-Iinclude` is a build-relative path used when building the SDK, it has nothing to do with how users should include the SDK. One can even imagine scenarios where not only this path is useless, but it could also incorrectly include a random directory in users builds.

### Reproduction Steps

Any regular build will showcase the incorrect behavior:
```
$ mkdir build
$ cd build
$ cmake .. -DBUILD_ONLY=s3
$ make
$ make install
$ cat /usr/local/lib/pkgconfig/aws-cpp-sdk-s3.pc
includedir=include
libdir=lib

Name: aws-cpp-sdk-s3
Description:
Version: 1.11.165
Cflags: -I${includedir} -fno-exceptions -std=c++11
Libs: -L${libdir} -laws-cpp-sdk-s3
Libs.private:
Requires: aws-cpp-sdk-core
$ cat /usr/local/lib/pkgconfig/aws-cpp-sdk-core.pc
includedir=include
libdir=lib

Name: aws-cpp-sdk-core
Description:
Version: 1.11.165
Cflags: -I${includedir} -fno-exceptions -std=c++11
Libs: -L${libdir} -laws-cpp-sdk-core
Libs.private: -laws-crt-cpp -laws-c-auth -laws-c-cal -laws-c-common -laws-c-compression -laws-c-event-stream -laws-c-http -laws-c-io -laws-c-mqtt -laws-c-s3 -laws-checksums -laws-c-sdkutils -lpthread -lcurl -lcrypto -lssl -lz
Requires:
```

### Possible Solution

- Remove SDK-specific build flags (specifically `-std=c++11` and `-fno-exceptions`) here: https://github.com/aws/aws-sdk-cpp/blob/197a6dfde08071bec386518eb1aa1631903d198d/cmake/compiler_settings.cmake#L23
- Use proper **installation** directories, not **build** directories (I guess that would be `@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@` or something like that) here: https://github.com/aws/aws-sdk-cpp/blob/197a6dfde08071bec386518eb1aa1631903d198d/toolchains/pkg-config.pc.in#L1

### Additional Information/Context

_No response_

### AWS CPP SDK version used

Any

### Compiler and Version used

Any

### Operating System and version

Any linux

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da toolchains/pkg-config.pc.in e cmake/compiler_settings.cmake, quindi riproduci il problema con una build e un'installazione CMake che utilizzino solo S3. Esamina i file generati aws-cpp-sdk-s3.pc e aws-cpp-sdk-core.pc; il lavoro è completato quando contengono i percorsi di include e delle librerie dell'installazione e solo i flag rivolti al consumer mostrati nell'output previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cmake, cpp
Ambito
build-system
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.