Skip to content

Commit 1da9687

Browse files
committed
feat: add support for macOS prebuilt versions and update related configurations
1 parent 061b0cc commit 1da9687

8 files changed

Lines changed: 261 additions & 18 deletions

File tree

.github/workflows/e2e_test_darwin_prebuilt.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
3939
- name: install Erlang/OTP by vfox-erlang plugin (Darwin prebuilt)
4040
run: |
41-
export USE_PREBUILT_OTP="macos-13"
41+
export USE_PREBUILT_OTP="1"
4242
vfox install erlang@26.2.3
4343
vfox use -g erlang@26.2.3
4444
eval "$(vfox activate bash)"

.gitignore

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

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
![logo](./assets/vfox-erlang-logo.png)
44

5-
[![E2E tests on Linux](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_linux.yaml/badge.svg)](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_linux.yaml) [![E2E tests on Darwin MacOS](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_darwin.yaml/badge.svg)](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_darwin.yaml) [![E2E tests on Windows](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_windows.yaml/badge.svg)](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_windows.yaml)
5+
[![E2E tests on Linux](https://github.com### MacOS
6+
7+
For MacOS, you can use prebuilt Erlang/OTP versions from [@erlef/otp_builds](https://github.com/erlef/otp_builds) by setting the `USE_PREBUILT_OTP` environment variable:
8+
9+
```shell
10+
# install a prebuilt version for MacOS (automatically detects architecture)
11+
USE_PREBUILT_OTP="1" vfox search erlang
12+
USE_PREBUILT_OTP="1" vfox install erlang@26.2.3
13+
```
14+
15+
**USE_PREBUILT_OTP** can be set to any non-empty value (e.g., "1", "true", "macos") to enable prebuilt mode.
16+
17+
Supported architectures: amd64, x86_64, arm64, aarch64. macOS uses a dedicated prebuilt version list that differs from the Ubuntu prebuilt versions.vfox-erlang/actions/workflows/e2e_test_linux.yaml/badge.svg)](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_linux.yaml) [![E2E tests on Darwin MacOS](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_darwin.yaml/badge.svg)](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_darwin.yaml) [![E2E tests on Windows](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_windows.yaml/badge.svg)](https://github.com/version-fox/vfox-erlang/actions/workflows/e2e_test_windows.yaml)
618

719
</div>
820

@@ -103,12 +115,14 @@ USE_PREBUILT_OTP="ubuntu-20.04" vfox install erlang@26.2.3
103115

104116
### MacOS
105117

106-
For MacOS, you can use prebuilt Erlang/OTP versions from [@erlef/otp_builds](https://github.com/erlef/otp_builds):
118+
For MacOS, you can use prebuilt Erlang/OTP versions from [@erlef/otp_builds](https://github.com/erlef/otp_builds) by setting the `USE_PREBUILT_OTP` environment variable:
107119

108120
```shell
109-
# install a prebuilt version for MacOS
110-
USE_PREBUILT_OTP="macos-13" vfox search erlang
111-
USE_PREBUILT_OTP="macos-13" vfox install erlang@26.2.3
121+
# install a prebuilt version for MacOS (automatically detects architecture)
122+
USE_PREBUILT_OTP="1" vfox search erlang
123+
USE_PREBUILT_OTP="1" vfox install erlang@26.2.3
112124
```
113125

114-
**USE_PREBUILT_OTP** var value for MacOS is one of: ["macos-11", "macos-12", "macos-13", "macos-14"].
126+
**USE_PREBUILT_OTP** can be set to any non-empty value (e.g., "1", "true", "macos") to enable prebuilt mode.
127+
128+
Supported architectures: amd64, x86_64, arm64, aarch64. macOS uses a dedicated prebuilt version list that differs from the Ubuntu prebuilt versions.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Get macOS prebuilt versions list
4+
Fetch all available macOS prebuilt versions from @erlef/otp_builds GitHub repository
5+
"""
6+
7+
import urllib.request
8+
import json
9+
10+
def get_macos_prebuilt_versions():
11+
"""Fetch all available macOS prebuilt versions from erlef/otp_builds"""
12+
13+
# GitHub API URL for releases
14+
api_url = "https://api.github.com/repos/erlef/otp_builds/releases"
15+
16+
all_versions = []
17+
page = 1
18+
19+
try:
20+
while True:
21+
print(f"Fetching page {page}...")
22+
url = f"{api_url}?page={page}&per_page=100"
23+
24+
with urllib.request.urlopen(url) as response:
25+
if response.status != 200:
26+
break
27+
28+
releases = json.loads(response.read().decode())
29+
if not releases:
30+
break
31+
32+
for release in releases:
33+
tag_name = release["tag_name"]
34+
assets = release["assets"]
35+
36+
# Check if there are macOS related assets
37+
has_macos_assets = False
38+
for asset in assets:
39+
asset_name = asset["name"]
40+
# Check if contains macOS related filename patterns
41+
if any(pattern in asset_name.lower() for pattern in [
42+
"macos", "darwin", "osx",
43+
"aarch64-apple", "x86_64-apple",
44+
"arm64.tar.gz", "amd64.tar.gz"
45+
]):
46+
has_macos_assets = True
47+
break
48+
49+
if has_macos_assets:
50+
all_versions.append(tag_name)
51+
print(f"Found macOS version: {tag_name}")
52+
53+
page += 1
54+
# Limit maximum pages to avoid infinite loop
55+
if page > 20:
56+
break
57+
58+
except Exception as e:
59+
print(f"Error fetching data: {e}")
60+
return []
61+
62+
return all_versions
63+
64+
def main():
65+
print("Fetching macOS prebuilt versions from erlef/otp_builds...")
66+
versions = get_macos_prebuilt_versions()
67+
68+
if versions:
69+
print(f"\nFound {len(versions)} macOS prebuilt versions:")
70+
71+
# Sort by version number (simple string sorting)
72+
versions.sort(reverse=True)
73+
74+
# Save to file
75+
with open("macos_prebuilt_versions.txt", "w", encoding="utf-8") as f:
76+
for version in versions:
77+
f.write(version + "\n")
78+
print(version)
79+
80+
print("\nVersions saved to macos_prebuilt_versions.txt")
81+
else:
82+
print("No macOS prebuilt versions found.")
83+
84+
if __name__ == "__main__":
85+
main()

assets/macos_prebuilt_versions.txt

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
master-latest
2+
maint-latest
3+
maint-27-latest
4+
maint-26-latest
5+
maint-25-latest
6+
OTP-28.0.1
7+
OTP-28.0-rc4
8+
OTP-28.0-rc3
9+
OTP-28.0-rc2
10+
OTP-28.0-rc1
11+
OTP-28.0
12+
OTP-27.3.4.1
13+
OTP-27.3.4
14+
OTP-27.3.3
15+
OTP-27.3.2
16+
OTP-27.3.1
17+
OTP-27.3
18+
OTP-27.2.4
19+
OTP-27.2.3
20+
OTP-27.2.2
21+
OTP-27.2.1
22+
OTP-27.2
23+
OTP-27.1.3
24+
OTP-27.1.2
25+
OTP-27.1.1
26+
OTP-27.1
27+
OTP-27.0.1
28+
OTP-27.0-rc3
29+
OTP-27.0-rc2
30+
OTP-27.0-rc1
31+
OTP-27.0
32+
OTP-26.2.5.9
33+
OTP-26.2.5.8
34+
OTP-26.2.5.7
35+
OTP-26.2.5.6
36+
OTP-26.2.5.5
37+
OTP-26.2.5.4
38+
OTP-26.2.5.3
39+
OTP-26.2.5.2
40+
OTP-26.2.5.13
41+
OTP-26.2.5.12
42+
OTP-26.2.5.11
43+
OTP-26.2.5.10
44+
OTP-26.2.5.1
45+
OTP-26.2.5
46+
OTP-26.2.4
47+
OTP-26.2.3
48+
OTP-26.2.2
49+
OTP-26.2.1
50+
OTP-26.2
51+
OTP-26.1.2
52+
OTP-26.1.1
53+
OTP-26.1
54+
OTP-26.0.2
55+
OTP-26.0.1
56+
OTP-26.0-rc3
57+
OTP-26.0-rc2
58+
OTP-26.0-rc1
59+
OTP-26.0
60+
OTP-25.3.2.9
61+
OTP-25.3.2.8
62+
OTP-25.3.2.7
63+
OTP-25.3.2.6
64+
OTP-25.3.2.5
65+
OTP-25.3.2.4
66+
OTP-25.3.2.3
67+
OTP-25.3.2.21
68+
OTP-25.3.2.20
69+
OTP-25.3.2.2
70+
OTP-25.3.2.19
71+
OTP-25.3.2.18
72+
OTP-25.3.2.17
73+
OTP-25.3.2.16
74+
OTP-25.3.2.15
75+
OTP-25.3.2.14
76+
OTP-25.3.2.13
77+
OTP-25.3.2.12
78+
OTP-25.3.2.11
79+
OTP-25.3.2.10
80+
OTP-25.3.2.1
81+
OTP-25.3.2
82+
OTP-25.3.1
83+
OTP-25.3
84+
OTP-25.2.3
85+
OTP-25.2.2
86+
OTP-25.2.1
87+
OTP-25.2
88+
OTP-25.1.2.1
89+
OTP-25.1.2
90+
OTP-25.1.1
91+
OTP-25.1
92+
OTP-25.0.4
93+
OTP-25.0.3
94+
OTP-25.0.2
95+
OTP-25.0.1
96+
OTP-25.0-rc3
97+
OTP-25.0-rc2
98+
OTP-25.0-rc1
99+
OTP-25.0

hooks/pre_install.lua

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,30 @@ function PLUGIN:PreInstall(ctx)
3030
"Make sure the USE_PREBUILT environment variable is set to one of the following values: ubuntu-20.04, ubuntu-22.04, ubuntu-24.04")
3131
end
3232
download_url = "https://builds.hex.pm/builds/otp/" .. RUNTIME.archType .. "/" .. PRE_BUILT_OS_RELEASE .. "/" .. erlang_version .. ".tar.gz"
33-
elseif RUNTIME.osType == "darwin" and PRE_BUILT_OS_RELEASE then
34-
local SUPPORT_MACOS_RELEASE = { "macos-11", "macos-12", "macos-13", "macos-14" }
35-
if not erlangUtils.array_contains(SUPPORT_MACOS_RELEASE, PRE_BUILT_OS_RELEASE) then
36-
error(
37-
"Make sure the USE_PREBUILT_OTP environment variable is set to one of the following values for MacOS: macos-11, macos-12, macos-13, macos-14")
38-
end
33+
elseif RUNTIME.osType == "darwin" and erlangUtils.get_config_from_env("USE_PREBUILT_OTP") then
3934
-- Use @erlef/otp_builds for MacOS prebuilt binaries
40-
download_url = "https://github.com/erlef/otp_builds/releases/download/OTP-" .. erlang_version .. "/otp_" .. PRE_BUILT_OS_RELEASE .. "_" .. RUNTIME.archType .. ".tar.gz"
35+
local arch_mapping = {
36+
amd64 = "amd64",
37+
x86_64 = "x86_64",
38+
arm64 = "arm64",
39+
aarch64 = "aarch64"
40+
}
41+
42+
local mapped_arch = arch_mapping[RUNTIME.archType]
43+
if not mapped_arch then
44+
error("Unsupported architecture for prebuilt MacOS binaries: " .. RUNTIME.archType .. ". Supported architectures: amd64, x86_64, arm64, aarch64")
45+
end
46+
47+
-- Use different URL patterns based on architecture
48+
if mapped_arch == "aarch64" then
49+
download_url = "https://github.com/erlef/otp_builds/releases/download/OTP-" .. erlang_version .. "/otp-aarch64-apple-darwin.tar.gz"
50+
elseif mapped_arch == "arm64" then
51+
download_url = "https://github.com/erlef/otp_builds/releases/download/OTP-" .. erlang_version .. "/OTP-" .. erlang_version .. "-macos-arm64.tar.gz"
52+
elseif mapped_arch == "amd64" then
53+
download_url = "https://github.com/erlef/otp_builds/releases/download/OTP-" .. erlang_version .. "/OTP-" .. erlang_version .. "-macos-amd64.tar.gz"
54+
elseif mapped_arch == "x86_64" then
55+
download_url = "https://github.com/erlef/otp_builds/releases/download/OTP-" .. erlang_version .. "/otp-x86_64-apple-darwin.tar.gz"
56+
end
4157
else
4258
download_url = "https://github.com/erlang/otp/archive/refs/tags/OTP-" .. erlang_version .. ".tar.gz"
4359
end

lib/erlang_utils.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@ end
6060
function erlang_utils.get_erlang_release_verions()
6161
local search_url = "https://fastly.jsdelivr.net/gh/version-fox/vfox-erlang@main/assets/versions.txt"
6262

63-
if erlang_utils.get_config_from_env("USE_PREBUILT_OTP") then
64-
-- search_url = "http://localhost:3000/prebuilt_versions.txt"
65-
search_url = "https://fastly.jsdelivr.net/gh/version-fox/vfox-erlang@main/assets/prebuilt_versions.txt"
63+
-- Use prebuilt versions when USE_PREBUILT_OTP is explicitly set
64+
local use_prebuilt = erlang_utils.get_config_from_env("USE_PREBUILT_OTP")
65+
if use_prebuilt then
66+
-- Choose different prebuilt version lists based on platform
67+
if RUNTIME.osType == "darwin" then
68+
-- Use macOS specific prebuilt versions
69+
search_url = "https://fastly.jsdelivr.net/gh/version-fox/vfox-erlang@copilot/fix-64e3f5aa-3f9e-470f-ae99-95b41288ed0b/assets/macos_prebuilt_versions.txt"
70+
else
71+
-- Use Ubuntu prebuilt versions for Linux
72+
search_url = "https://fastly.jsdelivr.net/gh/version-fox/vfox-erlang@main/assets/prebuilt_versions.txt"
73+
end
6674
end
6775

6876
local resp, err = http.get({

test_macos_prebuilt.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
echo "Testing macOS prebuilt versions..."
3+
4+
echo "1. Testing without USE_PREBUILT_OTP (should use source versions):"
5+
cd /Users/yeshan333/.version-fox/plugin/erlang
6+
export USE_PREBUILT_OTP=""
7+
curl -s "https://fastly.jsdelivr.net/gh/version-fox/vfox-erlang@main/assets/versions.txt" | head -5
8+
9+
echo ""
10+
echo "2. Testing with USE_PREBUILT_OTP for macOS (should use macOS prebuilt versions):"
11+
export USE_PREBUILT_OTP="1"
12+
curl -s "https://fastly.jsdelivr.net/gh/version-fox/vfox-erlang@main/assets/macos_prebuilt_versions.txt" | head -5
13+
14+
echo ""
15+
echo "3. Testing macOS prebuilt versions file exists:"
16+
ls -la assets/macos_prebuilt_versions.txt
17+
18+
echo ""
19+
echo "4. First few lines of macOS prebuilt versions:"
20+
head -5 assets/macos_prebuilt_versions.txt

0 commit comments

Comments
 (0)