-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a proper build and package infrastructure.
- Loading branch information
1 parent
605ae5b
commit 0cec044
Showing
11 changed files
with
101 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
build/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
"editor.insertSpaces": true, | ||
"editor.tabSize": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
cmake_minimum_required (VERSION 3.5) | ||
project(libudev_stub) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
|
||
# libudev-stub requires a C++11 compiler | ||
include(CMakeForceCompiler) | ||
cmake_force_c_compiler(gcc-6 GCC) | ||
cmake_force_cxx_compiler(g++-6 GCC) | ||
|
||
set(CPACK_PACKAGE_VERSION_MAJOR 0) | ||
set(CPACK_PACKAGE_VERSION_MINOR 9) | ||
set(CPACK_PACKAGE_VERSION_PATCH 0) | ||
set(LIBUDEV_STUB_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") | ||
set(LIBUDEV_SOVERSION_MAJOR "1") | ||
set(LIBUDEV_SOVERSION "1.6.4") | ||
configure_file( | ||
"${PROJECT_SOURCE_DIR}/config.h.in" | ||
"${PROJECT_BINARY_DIR}/config.h" | ||
) | ||
|
||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out/lib") | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/out/bin") | ||
include_directories("${PROJECT_BINARY_DIR}") | ||
add_subdirectory(libudev) | ||
add_executable(libudev_test udev-test.cpp) | ||
target_link_libraries(libudev_test dl udev) | ||
target_link_libraries(libudev_test dl udev-stub) | ||
|
||
set(CPACK_GENERATOR "DEB") | ||
set(CPACK_SYSTEM_NAME "WSL") | ||
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/out/deb") | ||
set(CPACK_PACKAGING_INSTALL_PREFIX "/lib/x86_64-linux-gnu") | ||
set(CPACK_PACKAGE_NAME libudev-stub) | ||
set(CPACK_PACKAGE_VENDOR "community project") | ||
set(CPACK_PACKAGE_CONTACT "https://github.com/therealkenc/libudev-stub") | ||
set(CPACK_CMAKE_GENERATOR Ninja) | ||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "libudev stub library for WSL (${LIBUDEV_STUB_VERSION})") | ||
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/postinst") | ||
include(CPack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,39 @@ | ||
# libudev-stub | ||
**Libudev-stub** is a shim library for `libudev`, created primarily for the Windows Subsystem for Linux [WSL](https://msdn.microsoft.com/en-us/commandline/wsl/about). Theoretically it could be useful for other Linux-ish systems that lack udev support. [Udev](https://www.freedesktop.org/software/systemd/man/udev.html) is part of [systemd](https://www.freedesktop.org/wiki/Software/systemd/). It provides a well-known interface for device events (such as hot plugging of usb dongles and cameras) for many Linux distributions like [Ubuntu](https://www.ubuntu.com/). Unfortunately, WSL currently lacks much of the functionality required to support `udev`; at least as of [Windows Insider](https://insider.windows.com/) build 15046. | ||
[Libudev-stub](https://github.com/therealkenc/libudev-stub) is a shim library for `libudev`, created primarily for the Windows Subsystem for Linux [WSL](https://msdn.microsoft.com/en-us/commandline/wsl/about). Theoretically it could be useful for other Linux-ish systems that lack udev support. [Udev](https://www.freedesktop.org/software/systemd/man/udev.html) is part of [systemd](https://www.freedesktop.org/wiki/Software/systemd/). It provides a well-known interface for device events (such as hot plugging of usb dongles and cameras) for many Linux distributions like [Ubuntu](https://www.ubuntu.com/). Unfortunately, WSL currently lacks much of the functionality required to support `udev`; at least as of [Windows Insider](https://insider.windows.com/) build 15046. | ||
|
||
To work around this, `libudev-stub` implements a subset of the `libudev` interface that does not actually talk to the kernel. The theory of operation is pretty straightforward. When an application that uses `libudev` asks for a list of devices, the stub library says the list of devices is empty. When an application asks to monitor for device events, the library obliges, and then never raises any notifications. The code is structured in a way that devices could be faked, but it does not do so as of this initial relase. | ||
To work around this, `libudev-stub` implements a subset of the `libudev` interface that does not actually communicate with the kernel. The theory of operation is pretty straightforward. When an application uses `libudev` to ask for a list of devices, the stub library says there aren't any devices worth mentioning. When an application asks to monitor for device events, the library obliges, and then never raises any event notifications. The code is structured in a way that a static device list could be faked, but it does not do so as of this initial relase. | ||
|
||
That is just enough to make Google's [chromium](https://www.chromium.org/Home) happy, as well as by extension [libchromiumcontent](https://github.com/electron/libchromiumcontent) and [electron](https://electron.atom.io/). With `libudev-stub` installed, the out-of-the box version of [Chrome](https://www.google.com/chrome/) will run with the `--no-sandbox` command line option. | ||
All of which is just enough to make Google's [chromium](https://www.chromium.org/Home) happy, as well as by extension [libchromiumcontent](https://github.com/electron/libchromiumcontent) and [electron](https://electron.atom.io/). With `libudev-stub` installed, the out-of-the box version of [Chrome](https://www.google.com/chrome/) will run with the `--no-sandbox` command line option. | ||
|
||
Note however that graphical applications are [**not supported**](https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13250499-support-for-x-server-running-in-windows-on-the-sam?tracking_code=6be7122042c59b213451b9198f208f27) by Microsoft. You are on your own here until MSFT has cleared their development backlog of commandline development use case scenarios. | ||
Note however that graphical applications are [**not supported**](https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13250499-support-for-x-server-running-in-windows-on-the-sam?tracking_code=6be7122042c59b213451b9198f208f27) by Microsoft. You are _on your own_ here until MSFT has cleared their development backlog of commandline development use case scenarios. See the WSL [FAQ](https://msdn.microsoft.com/en-us/commandline/wsl/faq) for more. | ||
|
||
There is no fancy installer yet, but building is pretty painless. It requires a C++11 compiler. | ||
## Release installation | ||
The installer leaves the stock `libudev1` debian package in place, but changes the system `libudev.so.1` symlink to the `libudev-stub` version. This is harmless on WSL (since stock libudev doesn't work anyway), but you should not do this on a Real Ubuntu machine unless that is _really_ what you want. | ||
|
||
``` | ||
\# TODO release instructions once download url is ready | ||
wget <somewhere> | ||
sudo dpkg -i libudev-stub-0.9.0-WSL.deb | ||
``` | ||
|
||
## Source builds | ||
Builds require a C++11 compiler, so `install-deps.sh` will install g++-6 from [ppa:ubuntu-toolchain-r/test](https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test). This will **not** change your system's default compiler. | ||
``` | ||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test | ||
sudo apt-get update | ||
sudo apt-get install build-essential git cmake ninja-build libudev-dev gcc-6 g++-6 | ||
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 200 | ||
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 200 | ||
mkdir somewhere && cd somewhere | ||
git clone https://github.com/therealkenc/libudev-stub.git | ||
cd libudev-stub/build | ||
cmake -G Ninja .. | ||
ninja | ||
export LD_LIBRARY_PATH=$PWD/lib | ||
./scripts/install-deps.sh | ||
./scripts/build-all.sh | ||
``` | ||
This creates the `.deb` package in `build/out/deb`. The library file and symlinks live in `build/out/deb`. If you would rather not change your system `libudev.so.1`, you can manually set the `LD_LIBRARY_PATH` environment variable. For example: | ||
``` | ||
export LD_LIBRARY_PATH=./build/out/lib | ||
``` | ||
|
||
There is also an environment variable to turn the stub library into a passthrough proxy for the real `libudev.so.1`. It is useful to see where applications break when using the interface. Enable it with: | ||
## Hacking | ||
|
||
There is also an environment variable to turn the stub library into a passthrough proxy for the real `libudev.so.1`. It is useful to see where applications fail when using the `libudev` interface. Enable it with: | ||
``` | ||
export LIBUDEV_STUB_PASSTHROUGH=/lib/x86_64-linux-gnu/libudev.so.1 | ||
export LIBUDEV_STUB_PASSTHROUGH=/lib/x86_64-linux-gnu/libudev.so.1.6.4 | ||
``` | ||
<br><br><br> | ||
|
||
## ob-screenshot | ||
<img src="https://raw.githubusercontent.com/therealkenc/libudev-stub/master/docs/chrome-screencap.png" width="640"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define LIBUDEV_STUB_VERSION @LIBUDEV_STUB_VERSION@ | ||
#define LIBUDEV_SOVERSION_MAJOR @LIBUDEV_SOVERSION_MAJOR@ | ||
#define LIBUDEV_SOVERSION @LIBUDEV_SOVERSION@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
file(GLOB udev_src "*.cpp") | ||
add_library(udev SHARED ${udev_src}) | ||
set_property(TARGET udev PROPERTY SOVERSION 1) | ||
set_property(TARGET udev PROPERTY VERSION 1.6.4) | ||
add_library(udev-stub SHARED ${udev_src}) | ||
set_property(TARGET udev-stub PROPERTY SOVERSION "${LIBUDEV_SOVERSION_MAJOR}") | ||
set_property(TARGET udev-stub PROPERTY VERSION "${LIBUDEV_SOVERSION}") | ||
add_custom_command(TARGET udev-stub | ||
POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E create_symlink | ||
"${CMAKE_BINARY_DIR}/out/lib/libudev-stub.so.${LIBUDEV_SOVERSION}" | ||
"${CMAKE_BINARY_DIR}/out/lib/libudev.so.${LIBUDEV_SOVERSION_MAJOR}" | ||
) | ||
install(TARGETS udev-stub DESTINATION .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
#define STR_EXPAND(tok) #tok | ||
#define STR(tok) STR_EXPAND(tok) | ||
#define _public_ __attribute__ ((visibility("default"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
cmake -H. -B./build -G Ninja | ||
ninja -C ./build | ||
ninja -C ./build package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
sudo add-apt-repository ppa:ubuntu-toolchain-r/test | ||
sudo apt-get update | ||
sudo apt-get install build-essential git cmake ninja-build libudev-dev gcc-6 g++-6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
echo "symlink libudev.so.1 -> libudev-stub.so.1" | ||
ln -fs /lib/x86_64-linux-gnu/libudev-stub.so.1 /lib/x86_64-linux-gnu/libudev.so.1 |