Skip to content

Commit

Permalink
Linux: use new jextract option for libudev
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Feb 20, 2024
1 parent 7c8eeee commit 0326bb9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 14 deletions.
11 changes: 0 additions & 11 deletions java-does-usb/jextract/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,6 @@ On Linux, the limitations are:

- `sd-device.h` (header file for *libsystemd*): *jextract* fails with *"Error: /usr/include/inttypes.h:290:8: error: unknown type name 'intmax_t'"*. The reason is yet unknown. This code is currently not needed as *libudev* is used instead of *libsystemd*. They are related, *libsystemd* is the future solution, but it is missing support for monitoring devices.

- `libudev.h`: After code generation, the class `udev` in `.../linux/gen/udev` must be manually modified. In most Linux installations, there is no `libudev.so` alias to an actual version like `libudev.so.1.7.2`. The only alias is `libudev.so.1`. This is probably a deliberate decision by the authors as they do not plan to provide backward compatibility across major versions. But there does not seem to be a way to make *jextract* generate valid code for this setup. So manually replace:

```
static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("udev"), LIBRARY_ARENA)
```

with:

```
static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup("libudev.so.1", LIBRARY_ARENA)
```


## MacOS
Expand Down
2 changes: 1 addition & 1 deletion java-does-usb/jextract/linux/gen_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $JEXTRACT --output ../../src/main/java \
$JEXTRACT --output ../../src/main/java \
--header-class-name udev \
--target-package net.codecrete.usb.linux.gen.udev \
-l udev \
-l :libudev.so.1 \
--include-function udev_new \
--include-function udev_enumerate_new \
--include-function udev_enumerate_add_match_subsystem \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ static MemoryLayout align(MemoryLayout layout, long align) {
};
}

// Manually fix. Otherwise, libudev will not be found if "libudev-dev" is not installed
// static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("udev"), LIBRARY_ARENA)
static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup("libudev.so.1", LIBRARY_ARENA)
.or(SymbolLookup.loaderLookup())
.or(Linker.nativeLinker().defaultLookup());
Expand Down

0 comments on commit 0326bb9

Please sign in to comment.