Skip to content

Commit

Permalink
Support arm64 runtime
Browse files Browse the repository at this point in the history
We add <OS>_<Platform> blocks to the installer; these override the <OS>
and "all" blocks (in that order). This allows us to download different
binaries for different platforms, but for mostly the configuration to
remain per-OS.

This works on arm64 Mac and in the docker container on linux arm64 (sort
of; there's some bug where 'love' won't install in the container).
  • Loading branch information
puremourning committed Nov 17, 2021
1 parent 14fc109 commit fb752df
Show file tree
Hide file tree
Showing 10 changed files with 2,937 additions and 36 deletions.
3 changes: 2 additions & 1 deletion doc/vimspector-ref.txt
Expand Up @@ -374,7 +374,8 @@ abbreviations:
- '<vimspector home>' means the path to the Vimspector installation (such as
'$HOME/.vim/pack/vimspector/start/vimspector')

- '<OS>' is either 'macos' or 'linux' depending on the host operating system.
- '<OS>' is either 'macos', 'linux' or 'windows' depending on the host
operating system.

- '<filetype>' is the Vim filetype. Where multiple filetypes are in effect,
typically all filetypes are checked.
Expand Down
3 changes: 3 additions & 0 deletions docs/custom_gadget_file.md
Expand Up @@ -23,3 +23,6 @@ like the supported adapters.
A _gadget definition_ is a file containing a single JSON object definition,
describing the debug adapter and how to download and install it. This mechanism
is crude but can be effective.

The definition of the file format is
[on the wiki](https://github.com/puremourning/vimspector/wiki/languages).
4 changes: 2 additions & 2 deletions install_gadget.py
Expand Up @@ -208,7 +208,7 @@
if not args.upgrade:
manifest.Clear( name )

installer.InstallGagdet( name,
installer.InstallGadget( name,
gadget,
manifest,
succeeded,
Expand All @@ -220,7 +220,7 @@
if not args.upgrade:
manifest.Clear( name )

installer.InstallGagdet( name,
installer.InstallGadget( name,
gadget,
manifest,
succeeded,
Expand Down
35 changes: 35 additions & 0 deletions python3/vimspector/core_utils.py
@@ -0,0 +1,35 @@
# vimspector - A multi-language debugging system for Vim
# Copyright 2021 Ben Jackson
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import functools

MEMO = {}


def memoize( func ):
global MEMO

@functools.wraps( func )
def wrapper( *args, **kwargs ):
dct = MEMO.setdefault( func, {} )
key = ( args, frozenset( kwargs.items() ) )
try:
return dct[ key ]
except KeyError:
result = func( *args, **kwargs )
dct[ key ] = result
return result

return wrapper
41 changes: 33 additions & 8 deletions python3/vimspector/gadgets.py
Expand Up @@ -30,7 +30,7 @@
root,
gadget ),
'all': {
'version': '1.6.0',
'version': '1.7.1',
"adapters": {
"vscode-cpptools": {
"name": "cppdbg",
Expand All @@ -53,17 +53,27 @@
'linux': {
'file_name': 'cpptools-linux.vsix',
'checksum':
'c25299bcfb46b22d41aa3f125df7184e6282a35ff9fb69c47def744cb4778f55',
'2ea9dd1bfbeff0b8153c45fa74692290307a33a2129dea36509efc8b35d515b9',
},
'linux_arm64': {
'file_name': 'cpptools-linux-aarch64.vsix',
'checksum':
'0136033788c805f09b56175926403a26a79857197ea4d6addd699e1a99ce9401',
},
'macos': {
'file_name': 'cpptools-osx.vsix',
'checksum':
'ae21cde361335b350402904991cf9f746fec685449ca9bd5d50227c3dec3719b',
'bab71db23b9221c6d5d40c7bb2243570ebe49a3bb7b9893033440681d27aa440',
},
'macos_arm64': {
'file_name': 'cpptools-osx-arm64.vsix',
'checksum':
'9dc7630463a9dce048bf96f30028f30a41889fea7be89c6d20cb93d156a9f3d6',
},
'windows': {
'file_name': 'cpptools-win32.vsix',
'checksum':
'ef7ac5831874a3c7dbf0feb826bfda2be579aff9b6d990622fff1d0d4ede00d1',
'469dcd619576cca700e917fef5e3f12ddce9d760d77e768042bd9566fadd71cb',
"adapters": {
"vscode-cpptools": {
"name": "cppdbg",
Expand All @@ -85,6 +95,11 @@
},
},
},
'windows_arm64': {
'file_name': 'cpptools-win-arm64.vsix',
'checksum':
'0427118d853d9262af824b28d102bbb6c11dc2eb66ff7f694336fd731ac404f7',
},
},
'debugpy': {
'language': 'python',
Expand Down Expand Up @@ -421,34 +436,44 @@
'${version}/${file_name}',
},
'all': {
'version': 'v1.6.7',
'version': 'v1.6.10',
},
'macos': {
'file_name': 'codelldb-x86_64-darwin.vsix',
'checksum':
'b652fc18f100f93ed1732a131f3dc519cbaf5ae688e9a91decf795203206497d',
'af17b80ccbf5fe57db3029302aabcd0ae04ed27d30b439dd34fb251b5f017a42',
'make_executable': [
'adapter/codelldb',
'lldb/bin/debugserver',
'lldb/bin/lldb',
'lldb/bin/lldb-argdumper',
],
},
'macos_arm64': {
'file_name': 'codelldb-aarch64-darwin.vsix',
'checksum':
'dda12566d5f39566aca81fd9b544faf89d3941d45e7cfdd97bb6492f883e2f96',
},
'linux': {
'file_name': 'codelldb-x86_64-linux.vsix',
'checksum':
'ca95479f9f6c9563aefb043e3bbacd7cc641b5915412df480ef9438b224d71ff',
'4166e97baa1f69c8eb4c2c9648a963c070d659e1c698a36a8bb729c3c432e53c',
'make_executable': [
'adapter/codelldb',
'lldb/bin/lldb',
'lldb/bin/lldb-server',
'lldb/bin/lldb-argdumper',
],
},
'linux_arm64': {
'file_name': 'codelldb-aarch64-linux.vsix',
'checksum':
'e8874a261dde885bae811cbbd739aca976ea1b5b89bd5ab6cc433ca56df51fbe',
},
'windows': {
'file_name': 'codelldb-x86_64-windows.vsix',
'checksum':
'0ae2559b4de4db592fb0eb44a2300e080cf802d3ea9970fe30835d4a63b5adc9',
'd2590b8634e8b388a49de7a3b171c20b20072ff3464418e608e91192f7ea24f8',
'make_executable': []
},
'adapters': {
Expand Down
31 changes: 31 additions & 0 deletions python3/vimspector/install.py
Expand Up @@ -15,8 +15,10 @@

import platform
import os
from vimspector.core_utils import memoize


@memoize
def GetOS():
if platform.system() == 'Darwin':
return 'macos'
Expand All @@ -26,6 +28,34 @@ def GetOS():
return 'linux'


@memoize
def GetPlatform():
machine = platform.machine()

try:
from vimspector.vendor import cpuinfo
except Exception:
return 'unknown'

machine_info = cpuinfo._parse_arch( machine )

machine_map = {
( 'X86_64', 64 ): 'x86_64',
( 'X86_32', 32 ): 'x86',
( 'ARM_8', 64 ): 'arm64',
}

try:
return machine_map[ machine_info ]
except KeyError:
return 'unknown'


@memoize
def GetOSPlatform():
return GetOS() + '_' + GetPlatform()


def mkdirs( p ):
try:
os.makedirs( p )
Expand All @@ -38,6 +68,7 @@ def MakeInstallDirs( vimspector_base ):
mkdirs( GetConfigDirForFiletype( vimspector_base, '_all' ) )


@memoize
def GetGadgetDir( vimspector_base ):
return os.path.join( os.path.abspath( vimspector_base ), 'gadgets', GetOS() )

Expand Down
10 changes: 6 additions & 4 deletions python3/vimspector/installer.py
Expand Up @@ -247,6 +247,7 @@ def FindGadgetForAdapter( adapter_name ):
v = {}
v.update( gadget.get( 'all', {} ) )
v.update( gadget.get( install.GetOS(), {} ) )
v.update( gadget.get( install.GetOSPlatform(), {} ) )

adapters = {}
adapters.update( v.get( 'adapters', {} ) )
Expand Down Expand Up @@ -414,7 +415,7 @@ def InstallTclProDebug( name, root, gadget ):
# '/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System'
# '/Library/Frameworks/Tcl.framework/Versions'
# '/Current',
for p in [ '/usr/local/opt/tcl-tk/lib' ]:
for p in [ '/usr/local/opt/tcl-tk/lib', '/opt/homebrew/opt/tcl-tk/lib' ]:
if os.path.exists( os.path.join( p, 'tclConfig.sh' ) ):
configure.append( '--with-tcl=' + p )
break
Expand All @@ -441,7 +442,7 @@ def InstallLuaLocal( name, root, gadget ):
MakeSymlink( name, root )


def InstallGagdet( name: str,
def InstallGadget( name: str,
gadget: dict,
manifest: Manifest,
succeeded: list,
Expand All @@ -453,6 +454,7 @@ def InstallGagdet( name: str,
spec = {}
spec.update( gadget.get( 'all', {} ) )
spec.update( gadget.get( install.GetOS(), {} ) )
spec.update( gadget.get( install.GetOSPlatform(), {} ) )

def save_adapters():
# allow per-os adapter overrides. v already did that for us...
Expand All @@ -462,8 +464,8 @@ def save_adapters():

if 'download' in gadget:
if 'file_name' not in spec:
raise RuntimeError( "Unsupported OS {} for gadget {}".format(
install.GetOS(),
raise RuntimeError( "Unsupported OS/platform {} for gadget {}".format(
install.GetOSPlatform(),
name ) )

print( f"Installing {name}@{spec[ 'version' ]}..." )
Expand Down
23 changes: 2 additions & 21 deletions python3/vimspector/utils.py
Expand Up @@ -19,13 +19,14 @@
import contextlib
import vim
import json
import functools
import subprocess
import shlex
import collections
import re
import typing

from vimspector.core_utils import memoize


LOG_FILE = os.path.expanduser( os.path.join( '~', '.vimspector.log' ) )

Expand Down Expand Up @@ -731,26 +732,6 @@ def Call( vimscript_function, *args ):
return vim.eval( call )


MEMO = {}


def memoize( func ):
global MEMO

@functools.wraps( func )
def wrapper( *args, **kwargs ):
dct = MEMO.setdefault( func, {} )
key = ( args, frozenset( kwargs.items() ) )
try:
return dct[ key ]
except KeyError:
result = func( *args, **kwargs )
dct[ key ] = result
return result

return wrapper


@memoize
def Exists( expr ):
return int( vim.eval( f'exists( "{ expr }" )' ) )
Expand Down

0 comments on commit fb752df

Please sign in to comment.