Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arm64 win32 support when building extension from source #982

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 28 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
- Python 3.5 or later.
- C++ compiler (GCC, clang or MSVC).
- Rust 1.61 or later.
- (Windows ARM64 cross-compile) `rustup target add aarch64-pc-windows-msvc`
- (Windows only) mingw-w64 toolchain (used for tests).
- (Windows ARM64 only) LLVM WOA64 (Windows on Arm64) such as [LLVM-16.0.6-woa64.exe](https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.6/LLVM-16.0.6-woa64.exe)

# Clone the repo
```
Expand All @@ -24,24 +26,47 @@ subdirectories from the build output.
# Configure

- On Windows, you should do this from "x64 Native Tools Command Prompt", so that MSVC environment is set up correctly.
- For arm64, use the "ARM64 Native Tools Command Prompt".
- On Mac, I recommend starting a new shell via `xcrun --sdk macosx zsh`

```
```sh
cd codelldb
mkdir build # (the build directory may be changed, but tasks.json assumes it's "build" under the project root)
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain-x86_64-linux-gnu.cmake -DLLDB_PACKAGE=<path to zip archive created in the previous step>
```
If you are on some other platform, edit the toolchain file accordingly. You *will* get linker errors if you don't use the toolchain file

## ARM64 Windows
```powershell
# Install LLVM For Windows on Arm64
iwr -Uri https://github.com/llvm/llvm-project/releases/download/llvmorg-16.0.6/LLVM-16.0.6-woa64.exe -OutFile LLVM-16.0.6-woa64.exe
.\LLVM-16.0.6-woa64.exe /S /D C:\LLVM
cd codelldb
mkdir build
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE="cmake/toolchain-aarch64-windows-msvc.cmake" -DLLDB_PACKAGE="C:\LLVM"

# Build the full extension to bundle the required binaries
cmake --build . --config Release --target vsix_full

# Install the extension
code --install-extension codelldb-full.vsix

# It is safe to uninstall LLVM once the extension is packed and installed
C:\LLVM\uninstall.exe
```

Windows on ARM64 will copy the bin and lib files from the LLVM package to the build directory.

# VSCode
If you intend to run and debug tests in VSCode, you may want to create a symlink from `<souce>/.cargo/config.toml`
to `<build>/.cargo/config.toml`.

# Build
```
```sh
cd build
make <target>
cmake --build . --target <target>
```

## Useful targets:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and Zig.
- Linux with glibc 2.18+ for x86_64, aarch64 or armhf.
- MacOS X 10.10+ for x86_64 and 11.0+ for arm64.
- Windows 10 and 11 for x86_64. [See Windows notes in wiki!](https://github.com/vadimcn/codelldb/wiki/Windows)
- Windows 10 and 11 arm64 is supported, but requires [building from source](./BUILDING.md#arm64-windows).

## Target
CodeLLDB supports AArch64, ARM, AVR, MSP430, RISCV, X86 architectures and may be used to debug on embedded platforms
Expand Down
8 changes: 5 additions & 3 deletions adapter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(ExternalProject)
add_subdirectory(scripts)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
find_file(MSDIA msdia140.dll PATHS "${CMAKE_SOURCE_DIR}" "$ENV{VSINSTALLDIR}/DIA SDK/bin/amd64" NO_DEFAULT_PATH)
find_file(MSDIA msdia140.dll PATHS "${CMAKE_SOURCE_DIR}" "$ENV{VSINSTALLDIR}/DIA SDK/bin/${TARGET_ARCH}" NO_DEFAULT_PATH)
if (NOT MSDIA) # Search again with default paths
find_file(MSDIA msdia140.dll)
endif()
Expand All @@ -12,11 +12,11 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
message(FATAL_ERROR "msdia140.dll not found")
else()
execute_process(COMMAND dumpbin "/headers" "${MSDIA}" OUTPUT_VARIABLE OUTPUT)
if (OUTPUT MATCHES ".*machine \\(x64\\).*")
if (OUTPUT MATCHES ".*machine \\(${HEADER_ARCH}\\).*")
message ("Found MSDIA at ${MSDIA}")
add_copy_file(DIAFiles "${MSDIA}" ${CMAKE_CURRENT_BINARY_DIR}/msdia140.dll)
else()
message(FATAL_ERROR "Found MSDIA at ${MSDIA}, but it isn't an x64 binary.")
message(FATAL_ERROR "Found MSDIA at ${MSDIA}, but it isn't an ${TARGET_ARCH} binary.")
endif()
endif()
endif()
Expand Down Expand Up @@ -78,6 +78,8 @@ else()
target_link_directories(codelldb_dylib PRIVATE ${CMAKE_BINARY_DIR}/lldb/lib)
target_link_libraries(codelldb_dylib PRIVATE liblldb.lib ws2_32.lib bcrypt.lib userenv.lib ntdll.lib)
target_link_options(codelldb_dylib PRIVATE /NODEFAULTLIB:MSVCRTD)
# Copy the dylib to binary directory for vsix_full to pick it up
add_custom_command(TARGET codelldb_dylib POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:codelldb_dylib> ${CMAKE_CURRENT_BINARY_DIR}/)
endif()
add_dependencies(codelldb_dylib cargo_build)
set_target_properties(codelldb_dylib PROPERTIES OUTPUT_NAME "codelldb")
Expand Down
6 changes: 6 additions & 0 deletions cmake/toolchain-aarch64-windows-msvc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(LLVM_TRIPLE aarch64-pc-windows-msvc)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(TARGET_ARCH arm64)
set(HEADER_ARCH ARM64)
set(CMAKE_GENERATOR_PLATFORM ARM64 CACHE INTERNAL "")
2 changes: 2 additions & 0 deletions cmake/toolchain-x86_64-windows-gnu.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(LLVM_TRIPLE x86_64-pc-windows-gnu)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(TARGET_ARCH amd64)
set(HEADER_ARCH x64)
2 changes: 2 additions & 0 deletions cmake/toolchain-x86_64-windows-msvc.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set(LLVM_TRIPLE x86_64-pc-windows-msvc)
set(CMAKE_C_COMPILER cl)
set(CMAKE_CXX_COMPILER cl)
set(TARGET_ARCH amd64)
set(HEADER_ARCH x64)
6 changes: 6 additions & 0 deletions cmake/toolchan-aarch64-windows-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(LLVM_TRIPLE aarch64-pc-windows-gnu)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(TARGET_ARCH arm64)
set(HEADER_ARCH ARM64)
set(CMAKE_GENERATOR_PLATFORM ARM64 CACHE INTERNAL "")
2 changes: 1 addition & 1 deletion extension/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function getPlatformPackageUrl(): Promise<Uri> {
let id = `${arch}-${platform}`;
let platformPackage = pp.platforms[id];
if (platformPackage == undefined) {
throw new Error(`This platform (${id}) is not suported.`);
throw new Error(`This platform (${id}) is not supported.`);
}
return Uri.parse(pp.url.replace('${version}', pkg.version).replace('${platformPackage}', platformPackage));
}
Expand Down
13 changes: 10 additions & 3 deletions lldb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ if(NOT IS_DIRECTORY ${LLDB_PACKAGE})
COMMAND unzip -o -u ${LLDB_PACKAGE} -d ${CMAKE_CURRENT_BINARY_DIR}
)
else()
message("${LLDB_PACKAGE} is a directory, symlinking.")
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/bin) # Remove dirs, if any
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/lib)
file(CREATE_LINK ${LLDB_PACKAGE}/bin ${CMAKE_CURRENT_BINARY_DIR}/bin SYMBOLIC)
file(CREATE_LINK ${LLDB_PACKAGE}/lib ${CMAKE_CURRENT_BINARY_DIR}/lib SYMBOLIC)
if(WIN32)
# Symbolic link does not work when installing the locally build vsix
message("${LLDB_PACKAGE} is a directory, copying.")
file(COPY ${LLDB_PACKAGE}/bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${LLDB_PACKAGE}/lib DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
else()
message("${LLDB_PACKAGE} is a directory, symlinking.")
file(CREATE_LINK ${LLDB_PACKAGE}/bin ${CMAKE_CURRENT_BINARY_DIR}/bin SYMBOLIC)
file(CREATE_LINK ${LLDB_PACKAGE}/lib ${CMAKE_CURRENT_BINARY_DIR}/lib SYMBOLIC)
endif()
endif()

# Create dependency check tests
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,8 @@
"x64-darwin": "codelldb-x86_64-darwin.vsix",
"arm64-darwin": "codelldb-aarch64-darwin.vsix",
"x64-win32": "codelldb-x86_64-windows.vsix",
"ia32-win32": "codelldb-x86_64-windows.vsix"
"ia32-win32": "codelldb-x86_64-windows.vsix",
"arm64-win32": "codelldb-arm64-windows.vsix"
}
}
}
Expand Down