22. April 2021

How to run Linux GUI application on Windows WSL2 with MobaXterm and Windows Terminal

MobaXterm is a great software that allows running applications from Linux on Windows in a nice integrated way without the need of installing extra XServer.

MobaXterm has also support for WSL2 which makes it easy to launch Linux GUI applications from Linux on Windows.

After installation of Linux distribution like Ubuntu or openSUSE on WSL2, you will find new sessions with the prefix WSL in MobaXterm. Simply click the session label and a new terminal will be automatically configured to talk to the local XServer.

Now you can start any GUI command, e.g. xeyes.

The same XServer from MobaXterm can be used also from other terminals and shells like Windows Terminal. It’s sufficient to export environment variable DISPLAY in the Linux WSL2 session:

export DISPLAY=127.0.0.1:0.0
xeyes

Note: xeyes are part of x11-apps, you can install them by command

sudo apt install x11-apps
Facebook Comments

20. April 2021

How to statically link Rust application for Windows

Rust compiler can generate a single binary that contains all dependencies. This is a great feature for creating stand-alone tools or tools for containers.

There is one gotcha for Windows which does not appear on a developer’s machine. When you move the application to a brand new installation of Windows or you try to start the in Windows Docker Container which contains Windows for Datacenters the app won’t start.

Why? The system is missing Microsoft Visual C++ Redistributable 2015-2019 (vc_redist) which you can download from microsoft.com.

It’s quite inconvenient to force the user to install the package in the case of a stand-alone Rust tool. The package installation even requires elevation of privileges.

The alternative approach to distributing vc_redist is to statically link CRT library into the application. It will result in a slightly bigger application around +100KB.

It’s necessary to tell rustc to perform static linking of CRT.

In the project create file .cargo/config.toml:

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

Rebuild the application and the new binary is statically linked and can run even on Windows 8 without vc_redist.

The interesting part is how to determine the proper target name which is on the first line of the example configuration. Many examples on the internet are referring to target.i686-pc-windows-msvc which does not work. Use the following command to determine parts of the name of the target:

rustc --print cfg
target_arch="x86_64"
target_endian="little"
target_env="msvc"
target_family="windows"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_os="windows"
target_pointer_width="64"
target_vendor="pc"
windows

The target name is composed of values on the lines above.

Facebook Comments

19. April 2021

How to do an ICMP ping of a Service in Kubernetes

When moving software to the cloud you may encounter a component that relies on good old ICMP ping.

The problem is that Kubernetes does not support ICMP ping between services. Nigel Poulton described reasons in his post.

But what if the software depends on ICMP ping because it’s hardcoded since days of the pre-cloud era?

One way to solve the problem and make ICMP ping between Service working in Kubernetes is to use the following trick which has two steps:
– open TCP tunnel which forwards a port of service to localhost
– define host alias in /etc/hosts pointing to 127.0.0.1

The trick is based on the simple idea that you can ping localhost and talk to the port with local address which is then forwarded to the desired address.

Commands to add ICMP ping to service “myservice”:

socat tcp-listen:8000,reuseaddr,fork tcp:myservice:8000
echo "127.0.0.1 myservice" >>/etc/hosts

Test:

ping myservice
nc -z myservice 8000

The solution is definitely not 100% bullet-proof, but it can be a good workaround until the software is fixed.

Facebook Comments

24. March 2021

How to download binary file in Rust by reqwest

reqwest in Rust allows you to download file. The question is how to store the file on the filesystem. There are several examples on the internet where authors are calling .text() which will result in a corrupted file on the filesystem because text() is decoding UTF-8 characters.

Here is an example of how to download a binary file and store content in a file on the local file system.

File download.rs:

use std::io::Cursor;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

async fn fetch_url(url: String, file_name: String) -> Result<()> {
    let response = reqwest::get(url).await?;
    let mut file = std::fs::File::create(file_name)?;
    let mut content =  Cursor::new(response.bytes().await?);
    std::io::copy(&mut content, &mut file)?;
    Ok(())
}

#[tokio::main]
async fn main() {
    fetch_url("https://georgik.rocks/wp-content/uploads/sianim.gif".to_string(), "siriel.gif".to_string()).await.unwrap();
}

File Cargo.toml:

[package]
name = "download"
version = "0.1.0"
authors = ["Georgik.Rocks"]
edition = "2018"

[dependencies]
reqwest = "*"
tokio = { version = "1", features = ["full"] }

[[bin]]
name = "download"
path = "download.rs"

To build the example type following:

cargo run
Facebook Comments

1. March 2021

Lenovo T14 CPU locked at 0.8 GHz on Windows

Users with brand new Lenovo T14 might face strange behavior on Windows. The computer seems to be slow and the detail of CPU usage displays a constant CPU speed set to 0.8 GHz.

The problem can be solved by upgrading BIOS. Drivers can be found at pcsupport.lenovo.com

Facebook Comments