Skip to content

Commit

Permalink
Merge pull request #60 from mikoto2000/add-support-other-arch
Browse files Browse the repository at this point in the history
ホストと異なるアーキテクチャのコンテナの実行に対応。
  • Loading branch information
mikoto2000 authored Dec 3, 2024
2 parents 159a1ca + a461769 commit d2a4335
Show file tree
Hide file tree
Showing 26 changed files with 443 additions and 587 deletions.
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@ WATCH_SRC := ./main.go \
./devcontainer/devcontainer.go \
./devcontainer/run.go \
./devcontainer/start.go \
./devcontainer/dockerRunVimArgs_darwin_arm64.go \
./devcontainer/dockerRunVimArgs_linux_amd64.go \
./devcontainer/dockerRunVimArgs_windows_amd64.go \
./devcontainer/devcontainerStartVimArgs_darwin_arm64.go \
./devcontainer/devcontainerStartVimArgs_linux_amd64.go \
./devcontainer/devcontainerStartVimArgs_windows_amd64.go \
./devcontainer/dockerRunVimArgs.go \
./devcontainer/devcontainerStartVimArgs.go \
./devcontainer/readConfigurationResult.go \
./devcontainer/upCommandResult.go \
./docker/docker.go \
./docker/dockerPsResult.go \
./dockercompose/dockerCompose.go \
./dockercompose/dockerComposePsResult.go \
./tools/tools.go \
./tools/vim_linux_amd64.go \
./tools/vim_darwin_arm64.go \
./tools/vim_windows_amd64.go \
./tools/nvim_linux_amd64.go \
./tools/nvim_darwin_arm64.go \
./tools/nvim_windows_amd64.go \
./tools/vim.go \
./tools/nvim.go \
./tools/devcontainer.go \
./tools/devcontainer_darwin.go \
./tools/devcontainer_linux.go \
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ endif

## Limitation:

- Windows, Linux では、amd64 のコンテナしか使用できません
- amd64 では、 alpine 系のコンテナでは使用できません
- macOS では、arm64 のコンテナしか使用できません
- alpine 系のコンテナでは amd64 アーキテクチャは使用できません
- macOS で NeoVim を利用する場合はシステムインストールされたものを利用する必要があります
- aarch64 のコンテナで NeoVim を利用する場合はシステムインストールされたものを利用する必要があります
- NeoVim AppImage が使えず、システムインストールの NeoVim も存在しない場合、 NeoVim の代わりに Vim が起動します
- macOS で NeoVim を利用する場合は、システムインストールの NeoVim しか利用できません
システムインストールの NeoVim が検出できなかった場合、代わりに Vim が起動します

Expand Down
10 changes: 5 additions & 5 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ endif

## Limitation:

- On Windows and Linux, only amd64 containers can be used.
- On amd64, alpine-based containers cannot be used.
- On macOS, only arm64 containers can be used.
- If you use NeoVim on macOS, you can only use the system-installed NeoVim.
If a system installed NeoVim cannot be detected, Vim will be launched instead.
- amd64 architecture cannot be used in alpine-based containers
- When using NeoVim in an aarch64 container, you must use the system-installed version
- If the NeoVim AppImage is not available and there is no system-installed NeoVim, Vim will start instead of NeoVim
- When using NeoVim on macOS, only the system-installed NeoVim can be used
If the system-installed NeoVim cannot be detected, Vim will start instead

## Install:

Expand Down
62 changes: 62 additions & 0 deletions devcontainer/devcontainerStartVimArgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package devcontainer

import "runtime"

// `devcontainer.vim start` 時の `devcontainer exec` の引数を組み立てる
//
// Args:
// - containerID: コンテナ ID
// - workspaceFolder: ワークスペースフォルダパス
// - vimFileName: コンテナ上に転送した vim/nvim のファイル名
// - useSystemVim: true の場合、システムにインストールした vim/nvim を利用する
//
// Return:
//
// `devcontainer exec` に使うコマンドライン引数の配列
func devcontainerStartVimArgs(containerID string, workspaceFolder string, vimFileName string, sendToTCP string, containerArch string, useSystemVim bool) []string {
if useSystemVim {
return []string{
"exec",
"--container-id",
containerID,
"--workspace-folder",
workspaceFolder,
"sh",
"-c",
vimFileName + " --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
} else {
if containerArch == "amd64" {
if runtime.GOOS != "darwin" {
return []string{
"exec",
"--container-id",
containerID,
"--workspace-folder",
workspaceFolder,
"sh",
"-c",
"cd ~; /" + vimFileName + " --appimage-extract > /dev/null; cd -; ~/squashfs-root/AppRun --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
} else {
return []string{
"exec",
"--container-id",
containerID,
"--workspace-folder",
workspaceFolder,
"sh",
"-c",
"cd /; tar zxf ./" + vimFileName + " -C ~/ > /dev/null; cd ~; sudo rm -rf ~/vim-static; mv $(ls -d ~/vim-*-x86_64) ~/vim-static;~/vim-static/AppRun --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
}
} else {
return []string{
"exec",
"--container-id",
containerID,
"--workspace-folder",
workspaceFolder,
"sh",
"-c",
"cd /; tar zxf ./" + vimFileName + " -C ~/ > /dev/null; cd ~; sudo rm -rf ~/vim-static; mv $(ls -d ~/vim-*-aarch64) ~/vim-static;~/vim-static/AppRun --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
}
}
}
38 changes: 0 additions & 38 deletions devcontainer/devcontainerStartVimArgs_darwin_arm64.go

This file was deleted.

38 changes: 0 additions & 38 deletions devcontainer/devcontainerStartVimArgs_linux_amd64.go

This file was deleted.

38 changes: 0 additions & 38 deletions devcontainer/devcontainerStartVimArgs_windows_amd64.go

This file was deleted.

53 changes: 53 additions & 0 deletions devcontainer/dockerRunVimArgs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package devcontainer

import "runtime"

// `devcontainer.vim run` 時の `docker exec` の引数を組み立てる
//
// Args:
// - containerID: コンテナ ID
// - vimFileName: コンテナ上に転送した vim のファイル名
// - useSystemVim: true の場合、システムにインストールされた vim/nvim を使用する
//
// Return:
//
// `docker exec` に使うコマンドライン引数の配列
func dockerRunVimArgs(containerID string, vimFileName string, sendToTCP string, containerArch string, useSystemVim bool) []string {
if useSystemVim {
return []string{
"exec",
"-it",
containerID,
"sh",
"-c",
vimFileName + " --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
} else {
if containerArch == "amd64" {
if runtime.GOOS != "darwin" {
return []string{
"exec",
"-it",
containerID,
"sh",
"-c",
"cd ~; /" + vimFileName + " --appimage-extract > /dev/null; cd -; ~/squashfs-root/AppRun --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
} else {
return []string{
"exec",
"-it",
containerID,
"sh",
"-c",
"cd /; tar zxf ./" + vimFileName + " -C ~/ > /dev/null; cd ~; sudo rm -rf ~/vim-static; mv $(ls -d ~/vim-*-x86_64) ~/vim-static;~/vim-static/AppRun --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
}
} else {
return []string{
"exec",
"-it",
containerID,
"sh",
"-c",
"cd /; tar zxf ./" + vimFileName + " -C ~/ > /dev/null; cd ~; sudo rm -rf ~/vim-static; mv $(ls -d ~/vim-*-aarch64) ~/vim-static;~/vim-static/AppRun --cmd \"let g:devcontainer_vim = v:true\" -S /" + sendToTCP + " -S /vimrc"}
}
}
}
33 changes: 0 additions & 33 deletions devcontainer/dockerRunVimArgs_darwin_arm64.go

This file was deleted.

33 changes: 0 additions & 33 deletions devcontainer/dockerRunVimArgs_linux_amd64.go

This file was deleted.

33 changes: 0 additions & 33 deletions devcontainer/dockerRunVimArgs_windows_amd64.go

This file was deleted.

Loading

0 comments on commit d2a4335

Please sign in to comment.