Skip to content

Commit 8e5e4e4

Browse files
authored
feat: support install Erlang/OTP in windows (#3)
* feat: support install Erlang/OTP in windows * chore: update e2e test for windows * chore: e2e push only trigger in main branch * docs: update README
1 parent 9915e63 commit 8e5e4e4

7 files changed

Lines changed: 108 additions & 41 deletions

File tree

.github/workflows/e2e_test.yaml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ name: E2E tests
33
on:
44
push:
55
branches: [main]
6+
pull_request:
67
workflow_dispatch:
78

89
jobs:
910
e2e_tests:
1011
strategy:
1112
matrix:
1213
# ref: https://github.com/actions/runner-images
13-
os: [ubuntu-20.04, macos-13]
14+
os: [ubuntu-20.04, macos-13, windows-2022]
1415
runs-on: ${{ matrix.os }}
1516
steps:
1617
- uses: actions/checkout@v4
@@ -27,10 +28,25 @@ jobs:
2728
run: |
2829
brew tap version-fox/tap
2930
brew install vfox
30-
31-
- name: add vfox-erlang plugin
31+
32+
- name: install scoop (Windows)
33+
if: runner.os == 'Windows'
34+
uses: MinoruSekine/setup-scoop@v3
35+
36+
- name: install vfox (Windows)
37+
if: runner.os == 'Windows'
38+
run: |
39+
scoop install vfox
40+
41+
- name: add vfox-erlang plugin (Unix-like)
42+
if: runner.os != 'Windows'
43+
run: |
44+
vfox add --source https://github.com/version-fox/vfox-erlang/archive/${GITHUB_REF}.zip erlang
45+
46+
- name: add vfox-erlang plugin (Windows)
47+
if: runner.os == 'Windows'
3248
run: |
33-
vfox add --source https://github.com/version-fox/vfox-erlang/archive/refs/heads/main.zip erlang
49+
vfox add --source https://github.com/version-fox/vfox-erlang/archive/$env:GITHUB_REF.zip erlang
3450
3551
- name: install Erlang/OTP by vfox-erlang plugin (Linux)
3652
if: runner.os == 'Linux'
@@ -58,4 +74,15 @@ jobs:
5874
echo "===============PATH==============="
5975
cd assets
6076
erlc hello.erl
61-
erl -noshell -s hello hello_world -s init stop
77+
erl -noshell -s hello hello_world -s init stop
78+
79+
- name: install etcd by vfox-etcd plugin (Windows)
80+
if: runner.os == 'Windows'
81+
run: |
82+
vfox install erlang@25.3.2.12
83+
vfox use erlang@25.3.2.12
84+
Invoke-Expression "$(vfox activate pwsh)"
85+
echo "===============PATH==============="
86+
echo $env:PATH
87+
echo "===============PATH==============="
88+
& erl.exe -eval 'erlang:display({otp_release, erlang:system_info(otp_release)}), halt().' -noshell

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
.tool-versions
3-
*.beam
3+
*.beam
4+
available.cache

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# vfox-erlang plugin
1010

11-
Erlang/OTP [vfox](https://github.com/version-fox) plugin. Use the vfox to manage multiple [Erlang/OTP](https://www.erlang.org/) versions in Linux/Darwin.
11+
Erlang/OTP [vfox](https://github.com/version-fox) plugin. Use the vfox to manage multiple [Erlang/OTP](https://www.erlang.org/) versions in Linux/Darwin MacOS/Windows. all platform~
1212

1313
## Usage
1414

@@ -22,7 +22,7 @@ vofx search erlang
2222
vfox install erlang@25.3.2.10
2323
```
2424

25-
## Before install Erlang/OTP
25+
## Before install Erlang/OTP in Linux/Darwin MacOS
2626

2727
vfox-erlang plugin would install Erlang/OTP through the [Erlang/OTP](https://www.erlang.org/doc/installation_guide/install#how-to-build-and-install-erlang-otp) source code compilation. So you must have the utilities mentioned in the document -> [Building and Installing Erlang/OTP](https://www.erlang.org/doc/installation_guide/install#how-to-build-and-install-erlang-otp).
2828

@@ -46,7 +46,7 @@ brew install autoconf libxslt fop wxwidgets openssl
4646

4747
You can reference the E2E test in MacOS 13: [https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml)
4848

49-
## Note
49+
### Note
5050

5151
By default, vfox-erlang plugin will Build [EEP-48 documentation chunks](https://www.erlang.org/doc/apps/kernel/eep48_chapter) for get doc in REPL (eg: h(list).) and [lsp docs hint](https://github.com/elixir-lsp/vscode-elixir-ls/issues/284).
5252

@@ -59,3 +59,19 @@ You cal also use the `OTP_CONFIGURE_ARGS` environment variable to control instal
5959
export OTP_CONFIGURE_ARGS="--enable-jit --enable-kernel-poll"
6060
vfox install erlang@25.3.2.10
6161
```
62+
63+
## install Erlang/OTP in Windows platform
64+
65+
In windows, the vfox-erlang plugin downloads the Erlang/OTP version of the exe installer from the [Erlang/OTP releases](https://github.com/erlang/otp/releases) and executes it for you.
66+
67+
This is an installation example in PowerShell:
68+
69+
```pwsh
70+
vfox install erlang@25.3.2.12
71+
vfox use erlang@25.3.2.12
72+
Invoke-Expression "$(vfox activate pwsh)"
73+
# Test the installation results
74+
& erl.exe -eval 'erlang:display({otp_release, erlang:system_info(otp_release)}), halt().' -noshell
75+
```
76+
77+
You can reference the E2E test in in windows-2022: [https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test.yaml)

hooks/env_keys.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
--- @field ctx.path string SDK installation directory
66
function PLUGIN:EnvKeys(ctx)
77
--- this variable is same as ctx.sdkInfo['plugin-name'].path
8-
local mainPath = ctx.path .. "/release/bin"
8+
local mainPath
9+
if RUNTIME.osType == "windows" then
10+
mainPath = ctx.path .. "\\release\\bin"
11+
else
12+
mainPath = ctx.path .. "/release/bin"
13+
end
14+
915
return {
1016
{
1117
key = "PATH",

hooks/post_install.lua

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,43 @@
33
--- Currently can be left unimplemented!
44
function PLUGIN:PostInstall(ctx)
55
--- ctx.rootPath SDK installation directory
6-
-- use ENV OTP_COMPILE_ARGS to control compile behavior
7-
local configure_args = os.getenv("OTP_CONFIGURE_ARGS") or ""
8-
print("Erlang/OTP compile configure args: %s", configure_args)
9-
10-
-- use ENV OTP_BUILD_DOCS to control bytecode with docs chunks
11-
local docs_target = os.getenv("DOC_TARGETS") or "chunks"
12-
13-
print("If you enable some Erlang/OTP features, maybe you can reference this guide: https://github.com/erlang/otp/blob/master/HOWTO/INSTALL.md#configuring-1")
14-
os.execute("sleep " .. tonumber(3))
15-
166
local sdkInfo = ctx.sdkInfo['erlang']
177
local path = sdkInfo.path
188

19-
local configure_cmd = "cd " .. path .. " && ./configure --prefix=" .. path .. "/release " .. configure_args
9+
if RUNTIME.osType == "windows" then
10+
local installer
11+
if RUNTIME.archType == "amd64" then
12+
installer = path .. "\\otp_win64_" .. sdkInfo.version .. ".exe"
13+
else
14+
installer = path .. "\\otp_win32_" .. sdkInfo.version .. ".exe"
15+
end
16+
17+
-- local install_cmd = "powershell Start-Process -FilePath " .. installer .. " -ArgumentList \"/S\", \"/D=" .. path .. "\" -Verb RunAs -Wait -PassThru -NoNewWindow"
18+
local install_cmd = installer .. " -Wait -PassThru" .. " /S /D=" .. path .. "\\release"
19+
print("install cmd: " .. install_cmd)
20+
local status = os.execute(install_cmd)
21+
if status ~= 0 then
22+
error("Erlang/OTP install failed, please check the stdout for details.")
23+
end
24+
else
25+
-- use ENV OTP_COMPILE_ARGS to control compile behavior
26+
local configure_args = os.getenv("OTP_CONFIGURE_ARGS") or ""
27+
print("Erlang/OTP compile configure args: %s", configure_args)
28+
29+
-- use ENV OTP_BUILD_DOCS to control bytecode with docs chunks
30+
local docs_target = os.getenv("DOC_TARGETS") or "chunks"
31+
32+
print("If you enable some Erlang/OTP features, maybe you can reference this guide: https://github.com/erlang/otp/blob/master/HOWTO/INSTALL.md#configuring-1")
33+
os.execute("sleep " .. tonumber(3))
34+
local configure_cmd = "cd " .. path .. " && ./configure --prefix=" .. path .. "/release " .. configure_args
2035

21-
local install_erlang_cmd = "cd " .. path .. "&& make && make install"
22-
-- install with docs chunk for IDE/REPL docs hits & type hits
23-
local install_erlang_docs_cmd = "cd " .. path .. " && make docs DOC_TARGETS=" .. docs_target .. " && make release_docs DOC_TARGETS=" .. docs_target
36+
local install_erlang_cmd = "cd " .. path .. "&& make && make install"
37+
-- install with docs chunk for IDE/REPL docs hits & type hits
38+
local install_erlang_docs_cmd = "cd " .. path .. " && make docs DOC_TARGETS=" .. docs_target .. " && make release_docs DOC_TARGETS=" .. docs_target
2439

25-
local status = os.execute(configure_cmd .. " && " .. install_erlang_cmd .. " && " ..install_erlang_docs_cmd)
26-
if status ~= 0 then
27-
error("Erlang/OTP install failed, please check the stdout for details. Make sure you have the required utilties: https://www.erlang.org/doc/installation_guide/install#required-utilities")
40+
local status = os.execute(configure_cmd .. " && " .. install_erlang_cmd .. " && " ..install_erlang_docs_cmd)
41+
if status ~= 0 then
42+
error("Erlang/OTP install failed, please check the stdout for details. Make sure you have the required utilties: https://www.erlang.org/doc/installation_guide/install#required-utilities")
43+
end
2844
end
2945
end

hooks/pre_install.lua

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ local erlangUtils = require("erlang_utils")
66
--- @field ctx.version string User-input version
77
--- @return table Version information
88
function PLUGIN:PreInstall(ctx)
9-
10-
erlangUtils.check_platform()
11-
129
local erlang_version = ctx.version
10+
print("You will install the Erlang/OTP version is: " .. erlang_version)
1311
if erlang_version == nil then
14-
print("You will install the Erlang/OTP version is" .. erlang_version)
1512
error("You must provide a version number for Erlang/OTP, eg: vfox install erlang@24.1")
1613
end
1714
erlangUtils.check_version_existence("https://github.com/erlang/otp/releases/tag/OTP-" .. erlang_version)
18-
19-
local download_url = "https://github.com/erlang/otp/archive/refs/tags/OTP-" .. erlang_version .. ".tar.gz"
15+
16+
local download_url
17+
if RUNTIME.osType == "windows" then
18+
if RUNTIME.archType == "amd64" then
19+
download_url = "https://github.com/erlang/otp/releases/download/OTP-" .. erlang_version .. "/otp_win64_" .. erlang_version .. ".exe"
20+
else
21+
download_url = "https://github.com/erlang/otp/releases/download/OTP-" .. erlang_version .. "/otp_win32_" .. erlang_version .. ".exe"
22+
end
23+
else
24+
download_url = "https://github.com/erlang/otp/archive/refs/tags/OTP-" .. erlang_version .. ".tar.gz"
25+
end
26+
2027
return {
2128
version = erlang_version,
2229
url = download_url

lib/erlang_utils.lua

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local erlang_utils = {}
44

55
local function peek_lua_table(o, indent)
66
indent = indent or 0
7-
7+
88
local function handle_table(t, currentIndent)
99
local result = {}
1010
for k, v in pairs(t) do
@@ -14,20 +14,14 @@ local function peek_lua_table(o, indent)
1414
end
1515
return '{\n' .. table.concat(result, ',\n') .. '\n' .. string.rep(' ', currentIndent) .. '}'
1616
end
17-
17+
1818
if type(o) == 'table' then
1919
return handle_table(o, indent)
2020
else
2121
return tostring(o)
2222
end
2323
end
2424

25-
function erlang_utils.check_platform()
26-
if RUNTIME.OS_TYPE == "windows" then
27-
error("Windows is not supported. Please direct use the offcial installer to setup Erlang/OTP. visit: https://www.erlang.org/downloads")
28-
end
29-
end
30-
3125
function erlang_utils.check_version_existence(url)
3226
local resp, err = http.get({
3327
url = url

0 commit comments

Comments
 (0)