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

[ffigen] Search dylib in conda env path #869

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/ffigen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ must be passed to change this behaviour.
- __Breaking change__: Stop generating setters for global variables marked `const` in C.
- Fix objc_msgSend being used on arm64 platforms where it's not available.
- Fix missing comma with `ffi-native` functions marked `leaf`.
- Add support for finding libclang in Conda environment.

## 10.0.0

Expand Down
19 changes: 18 additions & 1 deletion pkgs/ffigen/lib/src/config_provider/spec_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,27 @@ Headers headersExtractor(
);
}

String? _findLibInConda() {
final condaEnvPath = Platform.environment['CONDA_PREFIX'] ?? '';
lindeer marked this conversation as resolved.
Show resolved Hide resolved
lindeer marked this conversation as resolved.
Show resolved Hide resolved
if (condaEnvPath.isNotEmpty) {
final locations = [
p.join(condaEnvPath, 'lib'),
p.join(p.dirname(p.dirname(condaEnvPath)), 'lib'),
];
for (final l in locations) {
final k = findLibclangDylib(l);
if (k != null) return k;
}
}
return null;
}

/// Returns location of dynamic library by searching default locations. Logs
/// error and throws an Exception if not found.
String findDylibAtDefaultLocations() {
String? k;
// Assume clang in conda has a higher priority.
var k = _findLibInConda();
if (k != null) return k;
if (Platform.isLinux) {
for (final l in strings.linuxDylibLocations) {
k = findLibclangDylib(l);
Expand Down