Skip to content

Commit 4054a5c

Browse files
Ben HillisCopilot
andcommitted
Add wslc shell script for WSL interop
Add a shell script that allows WSL users to run 'wslc' without the .exe extension, similar to how VS Code ships a 'code' script alongside code.exe. The script resolves wslc.exe relative to its own location and forwards all arguments. - src/windows/wslc/wslc: new shell script - msipackage: include the script in the MSI package - test/windows/SimpleTests.cpp: add WslcShellScript smoke test Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9c4dba9 commit 4054a5c

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

msipackage/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ foreach(binary ${WINDOWS_BINARIES})
2727
list(APPEND BINARIES_DEPENDENCIES "${PACKAGE_INPUT_DIR}/${binary}")
2828
endforeach()
2929

30+
# Shell script for WSL interop (allows running 'wslc' without the .exe extension inside WSL)
31+
list(APPEND BINARIES_DEPENDENCIES "${CMAKE_SOURCE_DIR}/src/windows/wslc/wslc")
32+
3033
set(LINUX_BINARIES init;initrd.img)
3134
foreach(binary ${LINUX_BINARIES})
3235
list(APPEND BINARIES_DEPENDENCIES "${BIN}/${binary}")

msipackage/package.wix.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<File Id="wslg.exe" Name="wslg.exe" Source="${PACKAGE_INPUT_DIR}/wslg.exe" />
3030
<File Id="wslc.exe" Name="wslc.exe" Source="${PACKAGE_INPUT_DIR}/wslc.exe" />
31+
<File Id="wslc" Name="wslc" Source="${CMAKE_SOURCE_DIR}/src/windows/wslc/wslc" />
3132
<File Id="wslhost.exe" Name="wslhost.exe" Source="${PACKAGE_INPUT_DIR}/wslhost.exe" />
3233
<File Id="wslrelay.exe" Name="wslrelay.exe" Source="${PACKAGE_INPUT_DIR}/wslrelay.exe" />
3334
<File Id="wslserviceproxystub.dll" Name="wslserviceproxystub.dll" Source="${PACKAGE_INPUT_DIR}/wslserviceproxystub.dll" />

src/windows/wslc/.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Shell scripts must keep Unix (LF) line endings to work in WSL
2+
wslc text eol=lf

src/windows/wslc/wslc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Copyright (c) Microsoft. All rights reserved.
4+
#
5+
# Shell script to allow running wslc from within a WSL distribution
6+
# without needing the .exe extension (e.g. 'wslc' instead of 'wslc.exe').
7+
8+
WSL_PATH="$(dirname "$(realpath "$0")")"
9+
WSLC_EXE="$WSL_PATH/wslc.exe"
10+
11+
"$WSLC_EXE" "$@"
12+
exit $?

test/windows/SimpleTests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,14 @@ class SimpleTests
294294
VERIFY_IS_TRUE(output.find(L"/mnt/c/Program Files (x86)/Common Files") != std::wstring::npos);
295295
VERIFY_IS_TRUE(output.find(L"/mnt/c/Users/Test User/AppData/Local/Programs/Microsoft VS Code/bin") != std::wstring::npos);
296296
}
297+
298+
TEST_METHOD(WslcShellScript)
299+
{
300+
// Verify that the 'wslc' shell script (no .exe extension) invokes wslc.exe
301+
// and produces the same output as calling wslc.exe directly.
302+
auto [exeOutput, exeErr] = LxsstuLaunchWslAndCaptureOutput(L"wslc.exe version");
303+
auto [scriptOutput, scriptErr] = LxsstuLaunchWslAndCaptureOutput(L"wslc version");
304+
VERIFY_ARE_EQUAL(exeOutput, scriptOutput);
305+
}
297306
};
298307
} // namespace SimpleTests

0 commit comments

Comments
 (0)