Saturday, September 2, 2023

Developing code with WSL: 1 - Common problem

<WIP>

The two things Microsoft did recent years I would give a thumb up are WSL and VisualStudio Code. Both are gaining a lot of attraction along all software developers, I believe. Now, I'd like to make some note with WSL first. I had talked about WSL before, as:
Feb 2019: Running Linux on Windows

Jun 2020: Windows10 运行Ubuntu - WSL2

I'm going to create multiple post for what I learned while using WSL. This first one would be some common tips. 

Accessing files cross host Windows and WSL filesystem 

share folder: /mnt/c

running windows application

share git: cache issue

If user frequently or occasionally would switch between Windows and WSL, and run git command, may see that git will refresh index. As explained from this stackoverflow post:

  • The thing you're using here, which Git variously calls the index, the staging area, or the cache, does in fact contain cache data.

  • The cache data that it contains is the result of system calls.

  • The system call data returned by a Linux system is different from the system call data returned by a Windows system.

Especially if have VS-Code installed on Windows, and w/o using WSL extension to access the repo, VS-Code will run the windows native git.exe with the GitLens extension.

Another thing user may need to consider is: under WSL, the host Windows' git.exe is faster than the WSL linux git. So a simple and efficient solution would be set an alias by adding one line in ~/.bashrc file with:

alias git=git.exe

With this, under WSL it will always invoke the Windows git.exe for fetching the index. It's faster, no refresh when switch between Windows and WSL Linux. A side note is this won't work for tcl/expect which is used by the autobld script. This probably is due to the way how WSL is handling running navtive Windows app under WSL. For that, we can take the other approach mentioned in the same stackoverflow post: set environment variable of GIT_INDEX_FILE

 Makefile : Clock skew detected

Makefile : Clock skew detected - Stack Overflow, this is not the case for WSL build. In fact: WSL2 Clock is out of sync with Windows - Stack Overflow. Another easy way to get around this is: close all WSL session, then from a console, issue: wsl --shutdown. Then open a new WSL session, it will automatically sync the time with Windows host.

GUI: Windows 11, or MobaXterm and 32 bit/64bit executable

Refer to Run Linux on Windows - WSL

0 Comments:

Post a Comment