update: an x64 magpie emulated on Windows on Arm updates to the arm64 build (EV_John_Liu on X)
EV_John_Liu on X: "能不能出个windows on arm的版本啊…看到magpie是转译的".
magpie ships magpie-windows-arm64.exe and magpie-cli-windows-arm64.exe,
and the site's Windows button offers it on Arm, but an x64 install on an
Arm64 computer fetched the x64 build on every update and stayed emulated.
update's arch() swapped only an Intel Mac under Rosetta.
- internal/winarm: Emulated() asks IsWow64Process2 (x/sys/windows) once;
an amd64 build whose nativeMachine is IMAGE_FILE_MACHINE_ARM64 runs
emulated. A failed call (no IsWow64Process2 before Windows 10 1709)
means not emulated. false off Windows.
- update: arch() gives arm64 for windows/amd64 when emulated, so
BinaryAsset picks magpie-windows-arm64.exe (GUI) and
magpie-cli-windows-arm64.exe (CLI). The swap is the x64 one: canStart
starts the downloaded exe (it runs natively there), the running exe is
moved aside, the arm64 one renamed in under the same name, and
magpie.com is rewritten from the new app's own launcher.
- pii (sibling found on the way): pf-serve has no windows-arm64 build.
After the switch an arm64 magpie looked for a windows-arm64 pf-serve,
found none, and left Privacy Filter / AstrLink Guard "not downloaded"
while on. target() now maps windows-arm64 to the x64 pf-serve Windows 11
runs emulated; candidates() runs it on the CPU (the x64
pf-serve-vulkan has no x64 Vulkan driver there), then pf-serve-base
for an emulation without AVX2. The guard's status says emulated
(Status.Emulated), and its row reads "On, slowly under x64 emulation:
the next update installs magpie for Arm" in all five languages, like
the Rosetta line. app.js's and the core's script budgets grow by its
66 bytes.
- gui feedback: the diagnostics block's Arch line says
"amd64 (emulated on arm64)" / "amd64 (under Rosetta on arm64)".
Checked, not changed:
- site/public/index.html: the Windows main button already turns to
/download/windows-arm64 when userAgentData's architecture is "arm".
Run in Playwright Chromium and WebKit with a Windows Edge UA and
injected userAgentData: arm -> windows-arm64; x86 and no
userAgentData -> windows-amd64.
- telemetry (stats "arch") sends the build's GOARCH; left so, since what
is sent and the privacy text stay as they are. After the update it is
arm64 by itself.
- rtk: an arm64 magpie no longer upgrades a standalone x64 rtk.exe
(rtkArch == "amd64" only), filed as #6896.
- claudecode (win32-arm64) and Bun (windows-aarch64) downloads already
have arm64 builds.
Run (worktree at origin/main 17da22414):
- mote: go test -count=1 ./internal/winarm ./internal/update
./internal/pii ok; ./internal/gui -run Feedback ok.
- mote: go vet ./... ok; GOOS=linux go vet -tags nogui ./... ok;
GOOS=windows go vet ./... ok; GOOS=windows GOARCH=arm64 go vet of
winarm, update, pii, gui ok; darwin, windows and linux builds ok;
gofmt -l clean.
- mote: node --test privacy-model.test.cjs (Chromium and WebKit, five
languages, two widths) ok; i18n-keys' "a plugin's words are its own"
is red at this base on claude_image_budget_test.go's ", with an
image", already #6877.
- xiaomi-gpu (x64 Windows 11, real IsWow64Process2 saying not
emulated): win-run go test ./internal/winarm, ./internal/update -run
'WindowsOnArm|Rosetta|Asset|InstallBinary', ./internal/pii -run
'ArmWindows|GuardNow|Base', ./internal/gui -run Feedback ok.
- magpie-desktop (WSL2): winarm, update, pii ok; gui -tags nogui -run
Feedback ok.
- mote: go test -count=1 -tags nogui -timeout 45m ./... : every
package ok but internal/gui's TestCoreScriptBudget (app.js 66 bytes
over: the new pmSub line). The budgets are raised by those 66 with
why (pmSub draws every Privacy row, no lazy page to move it to);
internal/gui then ok in full.
- mote: gui-de, gui-ja, gui-zh-tw, i18n-en-no-cjk and the three other
privacy-*.test.cjs, in Chromium and WebKit: 28 of 28 each. Not the
whole GUI suite: the change is one string in one row, no API,
selector, CSS or layout.
Broken by hand (each red, then restored):
- arch() without the windows clause: TestWindowsOnArmUpdatesToArm64
(BinaryAsset magpie-windows-amd64.exe) and
TestWindowsOnArmInstallsArm64Exe (magpie.exe still "2.0 for x64").
- pii target() without the mapping: TestArmWindowsRunsX64Serve
(target windows-arm64, Supported false); candidates() without the
Arm branch: its subtests start pf-serve-vulkan.
- Status without Emulated: TestGuardNowSaysEmulated.
- archNote without the emulated case: TestFeedbackArchSaysTranslated.
- app.js without the emulated line: privacy-model's "AstrLink Guard
says what runs it" red in every language.
Not tried: real Windows on ARM (no such machine); detection is injected
in the tests, and the real call was only seen saying "not emulated" on
x64 Windows.
This commit is contained in:
@@ -22180,6 +22180,8 @@ function pmSub(m) {
|
||||
if (m.via) return { "Neural Engine": t("On, with CoreML on the Neural Engine"), GPU: t("On, with CoreML on the GPU"), CPU: t("On, with CoreML on the CPU") }[m.device] || t("On, with CoreML");
|
||||
// the Intel build on Apple silicon: Go, translated, several times slower
|
||||
if (m.rosetta) return t("On, slowly under Rosetta: the next update installs magpie for Apple silicon");
|
||||
// the x64 build on Windows on Arm, emulated
|
||||
if (m.emulated) return t("On, slowly under x64 emulation: the next update installs magpie for Arm");
|
||||
if (m.gpuError && m.model === "astrlink-guard") return t("On, on the CPU: CoreML failed ({error})", { error: m.gpuError });
|
||||
// Privacy Filter lost the GPU: to its driver resetting it (device
|
||||
// lost), or to a fault; the GPU is tried again at gpuAgain
|
||||
|
||||
@@ -1733,6 +1733,7 @@ const I18N = {
|
||||
"On, on the CPU until {time}: the graphics driver reset the GPU (device lost)": "已开启,{time} 前运行在 CPU:显卡驱动重置了 GPU(设备丢失)",
|
||||
"On, on the CPU": "已开启,运行在 CPU",
|
||||
"On, slowly under Rosetta: the next update installs magpie for Apple silicon": "已开启,但在 Rosetta 下运行较慢:下次更新会装上 Apple 芯片版 magpie",
|
||||
"On, slowly under x64 emulation: the next update installs magpie for Arm": "已开启,但在 x64 转译下运行较慢:下次更新会装上 ARM 版 magpie",
|
||||
"On, with CoreML on the Neural Engine": "已开启,通过 CoreML 运行在神经网络引擎",
|
||||
"On, with CoreML on the GPU": "已开启,通过 CoreML 运行在 GPU",
|
||||
"On, with CoreML on the CPU": "已开启,通过 CoreML 运行在 CPU",
|
||||
@@ -7093,6 +7094,7 @@ const I18N = {
|
||||
"On, on the CPU until {time}: the graphics driver reset the GPU (device lost)": "已開啟,{time} 前執行於 CPU:顯示卡驅動程式重設了 GPU(裝置遺失)",
|
||||
"On, on the CPU": "已開啟,執行於 CPU",
|
||||
"On, slowly under Rosetta: the next update installs magpie for Apple silicon": "已開啟,但在 Rosetta 下執行較慢:下次更新會裝上 Apple 晶片版 magpie",
|
||||
"On, slowly under x64 emulation: the next update installs magpie for Arm": "已開啟,但在 x64 模擬下執行較慢:下次更新會裝上 ARM 版 magpie",
|
||||
"On, with CoreML on the Neural Engine": "已開啟,透過 CoreML 執行於神經網路引擎",
|
||||
"On, with CoreML on the GPU": "已開啟,透過 CoreML 執行於 GPU",
|
||||
"On, with CoreML on the CPU": "已開啟,透過 CoreML 執行於 CPU",
|
||||
@@ -12421,6 +12423,7 @@ const I18N = {
|
||||
"On, on the CPU until {time}: the graphics driver reset the GPU (device lost)": "オン、{time} まで CPU で実行中:グラフィックスドライバーが GPU をリセットしました(デバイスロスト)",
|
||||
"On, on the CPU": "オン、CPU で実行中",
|
||||
"On, slowly under Rosetta: the next update installs magpie for Apple silicon": "オン、Rosetta で動作中のため低速です。次のアップデートで Apple シリコン版の magpie が入ります",
|
||||
"On, slowly under x64 emulation: the next update installs magpie for Arm": "オン、x64 エミュレーションで動作中のため低速です。次のアップデートで ARM 版の magpie が入ります",
|
||||
"On, with CoreML on the Neural Engine": "オン、CoreML により Neural Engine で実行中",
|
||||
"On, with CoreML on the GPU": "オン、CoreML により GPU で実行中",
|
||||
"On, with CoreML on the CPU": "オン、CoreML により CPU で実行中",
|
||||
@@ -17780,6 +17783,7 @@ const I18N = {
|
||||
"On, on the CPU until {time}: the graphics driver reset the GPU (device lost)": "An, bis {time} auf der CPU: der Grafiktreiber hat die GPU zurückgesetzt (Gerät verloren)",
|
||||
"On, on the CPU": "An, auf der CPU",
|
||||
"On, slowly under Rosetta: the next update installs magpie for Apple silicon": "An, unter Rosetta langsam: das nächste Update installiert magpie für Apple Silicon",
|
||||
"On, slowly under x64 emulation: the next update installs magpie for Arm": "An, unter x64-Emulation langsam: das nächste Update installiert magpie für Arm",
|
||||
"On, with CoreML on the Neural Engine": "An, mit CoreML auf der Neural Engine",
|
||||
"On, with CoreML on the GPU": "An, mit CoreML auf der GPU",
|
||||
"On, with CoreML on the CPU": "An, mit CoreML auf der CPU",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -10,6 +10,8 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/lazyre"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
"github.com/yetone/magpie/internal/rosetta"
|
||||
"github.com/yetone/magpie/internal/winarm"
|
||||
)
|
||||
|
||||
// FeedbackURL is the post on X where users reply with feedback; Settings ›
|
||||
@@ -50,6 +52,26 @@ func osVersion() string {
|
||||
return "Linux"
|
||||
}
|
||||
|
||||
// underRosetta and emulated say this build runs translated: an Intel one
|
||||
// on Apple silicon, an x64 one on Windows on Arm. Tests set them.
|
||||
var (
|
||||
underRosetta = rosetta.Translated
|
||||
emulated = winarm.Emulated
|
||||
)
|
||||
|
||||
// archNote is the architecture this build is for, and the computer's
|
||||
// where it runs translated there, which the next update ends (update's
|
||||
// arch): a report from such a computer says so, not just "amd64".
|
||||
func archNote() string {
|
||||
switch {
|
||||
case underRosetta():
|
||||
return runtime.GOARCH + " (under Rosetta on arm64)"
|
||||
case emulated():
|
||||
return runtime.GOARCH + " (emulated on arm64)"
|
||||
}
|
||||
return runtime.GOARCH
|
||||
}
|
||||
|
||||
// diagnostics is the block a report starts with. It holds the version, the
|
||||
// system, the architecture and where magpie is open, and never an account,
|
||||
// a key, a path or a user name: the user pastes it into a public reply.
|
||||
@@ -60,7 +82,7 @@ func diagnostics(surface string) string {
|
||||
return strings.Join([]string{
|
||||
"magpie " + Version,
|
||||
"OS: " + osVersion(),
|
||||
"Arch: " + runtime.GOARCH,
|
||||
"Arch: " + archNote(),
|
||||
"Opened in: " + surface,
|
||||
}, "\n")
|
||||
}
|
||||
|
||||
@@ -47,3 +47,25 @@ func TestFeedbackBlockHoldsNoPrivateFacts(t *testing.T) {
|
||||
t.Error("an unknown surface is not the app")
|
||||
}
|
||||
}
|
||||
|
||||
// A build that runs translated says so beside its architecture: an Intel
|
||||
// magpie under Rosetta, an x64 one under Windows on Arm's emulation
|
||||
// (@EV_John_Liu on X), each of which the next update replaces with the
|
||||
// arm64 build. A native one says its architecture alone.
|
||||
func TestFeedbackArchSaysTranslated(t *testing.T) {
|
||||
wasR, wasE := underRosetta, emulated
|
||||
t.Cleanup(func() { underRosetta, emulated = wasR, wasE })
|
||||
for _, c := range []struct {
|
||||
ros, em bool
|
||||
want string
|
||||
}{
|
||||
{false, false, "Arch: " + runtime.GOARCH + "\n"},
|
||||
{true, false, "Arch: " + runtime.GOARCH + " (under Rosetta on arm64)\n"},
|
||||
{false, true, "Arch: " + runtime.GOARCH + " (emulated on arm64)\n"},
|
||||
} {
|
||||
underRosetta, emulated = func() bool { return c.ros }, func() bool { return c.em }
|
||||
if got := diagnostics("app"); !strings.Contains(got, c.want) {
|
||||
t.Errorf("rosetta=%v emulated=%v: block lacks %q:\n%s", c.ros, c.em, c.want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,19 +100,22 @@ const scoreWords = {
|
||||
// where AstrLink Guard runs (yyhhyyyyyy on Discord: it said "on the CPU"
|
||||
// while CoreML ran it): CoreML on the device its plan picked, the CPU
|
||||
// with CoreML's error after a failed read, the CPU where there's no CoreML,
|
||||
// and a slow line with its fix under Rosetta
|
||||
// and a slow line with its fix under Rosetta and under Windows on Arm's
|
||||
// x64 emulation
|
||||
const runWords = {
|
||||
en: { ne: "On, with CoreML on the Neural Engine", gpu: "On, with CoreML on the GPU", ml: "On, with CoreML", failed: "On, on the CPU: CoreML failed (prediction failed)", cpu: "On, on the CPU", rosetta: "On, slowly under Rosetta: the next update installs magpie for Apple silicon" },
|
||||
zh: { ne: "已开启,通过 CoreML 运行在神经网络引擎", gpu: "已开启,通过 CoreML 运行在 GPU", ml: "已开启,通过 CoreML 运行", failed: "已开启,运行在 CPU:CoreML 出错(prediction failed)", cpu: "已开启,运行在 CPU", rosetta: "已开启,但在 Rosetta 下运行较慢:下次更新会装上 Apple 芯片版 magpie" },
|
||||
"zh-TW": { ne: "已開啟,透過 CoreML 執行於神經網路引擎", gpu: "已開啟,透過 CoreML 執行於 GPU", ml: "已開啟,透過 CoreML 執行", failed: "已開啟,執行於 CPU:CoreML 出錯(prediction failed)", cpu: "已開啟,執行於 CPU", rosetta: "已開啟,但在 Rosetta 下執行較慢:下次更新會裝上 Apple 晶片版 magpie" },
|
||||
ja: { ne: "オン、CoreML により Neural Engine で実行中", gpu: "オン、CoreML により GPU で実行中", ml: "オン、CoreML で実行中", failed: "オン、CPU で実行中:CoreML が失敗しました(prediction failed)", cpu: "オン、CPU で実行中", rosetta: "オン、Rosetta で動作中のため低速です。次のアップデートで Apple シリコン版の magpie が入ります" },
|
||||
de: { ne: "An, mit CoreML auf der Neural Engine", gpu: "An, mit CoreML auf der GPU", ml: "An, mit CoreML", failed: "An, auf der CPU: CoreML ist ausgefallen (prediction failed)", cpu: "An, auf der CPU", rosetta: "An, unter Rosetta langsam: das nächste Update installiert magpie für Apple Silicon" },
|
||||
en: { ne: "On, with CoreML on the Neural Engine", gpu: "On, with CoreML on the GPU", ml: "On, with CoreML", failed: "On, on the CPU: CoreML failed (prediction failed)", cpu: "On, on the CPU", rosetta: "On, slowly under Rosetta: the next update installs magpie for Apple silicon", emulated: "On, slowly under x64 emulation: the next update installs magpie for Arm" },
|
||||
zh: { ne: "已开启,通过 CoreML 运行在神经网络引擎", gpu: "已开启,通过 CoreML 运行在 GPU", ml: "已开启,通过 CoreML 运行", failed: "已开启,运行在 CPU:CoreML 出错(prediction failed)", cpu: "已开启,运行在 CPU", rosetta: "已开启,但在 Rosetta 下运行较慢:下次更新会装上 Apple 芯片版 magpie", emulated: "已开启,但在 x64 转译下运行较慢:下次更新会装上 ARM 版 magpie" },
|
||||
"zh-TW": { ne: "已開啟,透過 CoreML 執行於神經網路引擎", gpu: "已開啟,透過 CoreML 執行於 GPU", ml: "已開啟,透過 CoreML 執行", failed: "已開啟,執行於 CPU:CoreML 出錯(prediction failed)", cpu: "已開啟,執行於 CPU", rosetta: "已開啟,但在 Rosetta 下執行較慢:下次更新會裝上 Apple 晶片版 magpie", emulated: "已開啟,但在 x64 模擬下執行較慢:下次更新會裝上 ARM 版 magpie" },
|
||||
ja: { ne: "オン、CoreML により Neural Engine で実行中", gpu: "オン、CoreML により GPU で実行中", ml: "オン、CoreML で実行中", failed: "オン、CPU で実行中:CoreML が失敗しました(prediction failed)", cpu: "オン、CPU で実行中", rosetta: "オン、Rosetta で動作中のため低速です。次のアップデートで Apple シリコン版の magpie が入ります", emulated: "オン、x64 エミュレーションで動作中のため低速です。次のアップデートで ARM 版の magpie が入ります" },
|
||||
de: { ne: "An, mit CoreML auf der Neural Engine", gpu: "An, mit CoreML auf der GPU", ml: "An, mit CoreML", failed: "An, auf der CPU: CoreML ist ausgefallen (prediction failed)", cpu: "An, auf der CPU", rosetta: "An, unter Rosetta langsam: das nächste Update installiert magpie für Apple Silicon", emulated: "An, unter x64-Emulation langsam: das nächste Update installiert magpie für Arm" },
|
||||
};
|
||||
const runs = {
|
||||
ne: { via: "CoreML", device: "Neural Engine" }, gpu: { via: "CoreML", device: "GPU" }, ml: { via: "CoreML" },
|
||||
failed: { device: "CPU", gpuError: "prediction failed" }, cpu: { device: "CPU" },
|
||||
// the Intel build on Apple silicon (cdredfox on Discord: 150% of a core)
|
||||
rosetta: { device: "CPU", rosetta: true },
|
||||
// the x64 build on Windows on Arm (@EV_John_Liu on X)
|
||||
emulated: { device: "CPU", emulated: true },
|
||||
};
|
||||
|
||||
// Privacy Filter moved to the CPU after its GPU was lost (plugins#853,
|
||||
|
||||
@@ -14,13 +14,29 @@ var osArch = runtime.GOOS + "-" + runtime.GOARCH
|
||||
// Rosetta before macOS 15 has no AVX, so the Intel pf-serve ended with
|
||||
// SIGILL on its first instruction of it, on Metal and on the CPU alike
|
||||
// (echo_yip on X); Apple silicon's runs there natively, on Metal.
|
||||
//
|
||||
// On Windows on Arm it is the other way round: pf-serve has no arm64
|
||||
// build, and Windows 11 runs the x64 one emulated, as it ran the whole of
|
||||
// an x64 magpie there. The arm64 magpie an x64 one updates to (update's
|
||||
// arch) finds the x64 pf-serve already on disk and goes on with it; one
|
||||
// that found no pf-serve for windows-arm64 left the model "not
|
||||
// downloaded" while it was on in the settings.
|
||||
func target() string {
|
||||
if osArch == "darwin-amd64" && translated() {
|
||||
return "darwin-arm64"
|
||||
}
|
||||
if osArch == "windows-arm64" {
|
||||
return "windows-amd64"
|
||||
}
|
||||
return osArch
|
||||
}
|
||||
|
||||
// onArmWindows says pf-serve, the x64 one, runs emulated on Windows on
|
||||
// Arm, whose emulation may lack AVX2 (before Windows 11 24H2): fullX86
|
||||
// can't ask an x64 CPU there, so pf-serve is tried and then
|
||||
// pf-serve-base.
|
||||
func onArmWindows() bool { return osArch == "windows-arm64" }
|
||||
|
||||
// fullX86 says the CPU has what pf-serve is built for on x86 (build.sh's
|
||||
// x86): AVX, AVX2, FMA and BMI2, with F16C, which every CPU with AVX2
|
||||
// has. Without them pf-serve ends with SIGILL (a Celeron, a Pentium, a
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -146,3 +147,52 @@ func TestRosettaKeepsIntelsWhereNoneIsFetched(t *testing.T) {
|
||||
t.Fatalf("the Intel pf-serve was deleted: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// onArm runs the test as a magpie for windows-arm64: built for it, or the
|
||||
// x64 one updated to it on Windows on Arm (update's arch).
|
||||
func onArm(t *testing.T) {
|
||||
t.Helper()
|
||||
was := osArch
|
||||
t.Cleanup(func() { osArch = was })
|
||||
osArch = "windows-arm64"
|
||||
}
|
||||
|
||||
// pf-serve has no arm64 build: Windows on Arm runs the x64 one, emulated,
|
||||
// as it ran the x64 magpie that updated to arm64 there. Before, an arm64
|
||||
// magpie had no Privacy Filter, and the x64 one's update left the model
|
||||
// on in the settings and "not downloaded".
|
||||
func TestArmWindowsRunsX64Serve(t *testing.T) {
|
||||
onArm(t)
|
||||
if target() != "windows-amd64" || !Supported() {
|
||||
t.Fatalf("target = %s, Supported = %v on windows-arm64", target(), Supported())
|
||||
}
|
||||
if !strings.HasSuffix(serveDir(), "-windows-amd64") {
|
||||
t.Fatalf("serveDir = %s, not the x64 pf-serve's", serveDir())
|
||||
}
|
||||
// on the CPU: the x64 pf-serve-vulkan has no x64 Vulkan driver there
|
||||
t.Run("on the CPU", func(t *testing.T) {
|
||||
log := fakeInstall(t, "ok", true)
|
||||
noFullX86(t, true)
|
||||
if !Installed() {
|
||||
t.Fatal("the x64 pf-serve on disk isn't installed")
|
||||
}
|
||||
if _, err := Find([]string{"hi Alice"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve CPU"}) {
|
||||
t.Fatalf("starts = %q", starts)
|
||||
}
|
||||
})
|
||||
// an emulation without AVX2 ends pf-serve at once: pf-serve-base then
|
||||
t.Run("no AVX2", func(t *testing.T) {
|
||||
log := fakeInstall(t, "noavx2", true)
|
||||
withBase(t)
|
||||
noFullX86(t, true)
|
||||
if _, err := Find([]string{"hi Alice"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if starts := fakeLines(t, log, "start"); !reflect.DeepEqual(starts, []string{"start pf-serve CPU", "start pf-serve-base CPU"}) {
|
||||
t.Fatalf("starts = %q", starts)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ func (guardModel) Find(ctx context.Context, texts []string) ([][]redact.Found, e
|
||||
}
|
||||
|
||||
func (guardModel) Now() Status {
|
||||
s := Status{Model: AstrLinkGuard, Supported: true, Installed: guardInstalled(), Size: guardSize(), Rosetta: translated()}
|
||||
s := Status{Model: AstrLinkGuard, Supported: true, Installed: guardInstalled(), Size: guardSize(), Rosetta: translated(), Emulated: emulated()}
|
||||
gdl.fill(&s)
|
||||
gsrv.mu.Lock()
|
||||
if gsrv.m != nil {
|
||||
|
||||
@@ -422,3 +422,23 @@ func TestGuardNowSaysRosetta(t *testing.T) {
|
||||
t.Error("Privacy Filter says Rosetta, though its pf-serve is Apple silicon's")
|
||||
}
|
||||
}
|
||||
|
||||
// Now says when AstrLink Guard runs under Windows on Arm's x64 emulation,
|
||||
// as under Rosetta: the next update installs the arm64 magpie, where it
|
||||
// runs natively. Privacy Filter's pf-serve is x64 on either build, so it
|
||||
// says nothing.
|
||||
func TestGuardNowSaysEmulated(t *testing.T) {
|
||||
guardSandbox(t)
|
||||
was := emulated
|
||||
t.Cleanup(func() { emulated = was })
|
||||
for _, em := range []bool{false, true} {
|
||||
emulated = func() bool { return em }
|
||||
if st := Of(AstrLinkGuard).Now(); st.Emulated != em || st.Rosetta {
|
||||
t.Errorf("emulated=%v: AstrLink Guard's Emulated = %v, Rosetta = %v", em, st.Emulated, st.Rosetta)
|
||||
}
|
||||
}
|
||||
emulated = func() bool { return true }
|
||||
if st := Of(PrivacyFilter).Now(); st.Emulated {
|
||||
t.Error("Privacy Filter says emulated, though the update leaves its pf-serve x64")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ const (
|
||||
// badmodel says it couldn't read the model's file, by the name
|
||||
// it was given
|
||||
// novulkan as pf-serve-vulkan, says Vulkan is missing; else ok
|
||||
// noavx2 as pf-serve, ends at once as on a CPU (or an emulation)
|
||||
// without AVX2, SIGILL; else ok
|
||||
// gpuloadhang on the GPU, never says the model is loaded; else ok
|
||||
// asserts fails a ggml assert at its first request
|
||||
// gpuhang on the GPU, never answers a request; else ok
|
||||
@@ -94,6 +96,9 @@ func fakeServe(mode string) {
|
||||
json.NewEncoder(os.Stdout).Encode(map[string]string{"error": "failed to read GGUF: " + model})
|
||||
os.Exit(1)
|
||||
}
|
||||
if mode == "noavx2" && name == "pf-serve" {
|
||||
os.Exit(132)
|
||||
}
|
||||
if mode == "noload" || mode == "novulkan" && name == "pf-serve-vulkan" {
|
||||
json.NewEncoder(os.Stdout).Encode(map[string]string{"error": "can't load " + mode})
|
||||
os.Exit(1)
|
||||
|
||||
@@ -176,6 +176,9 @@ type Status struct {
|
||||
// in Go and translated, several times slower than in Apple silicon's
|
||||
// build, which has CoreML too
|
||||
Rosetta bool `json:"rosetta,omitempty"`
|
||||
// Emulated: AstrLink Guard runs in an x64 magpie under Windows on
|
||||
// Arm's emulation, translated as under Rosetta
|
||||
Emulated bool `json:"emulated,omitempty"`
|
||||
}
|
||||
|
||||
// Now is the model's status.
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package pii
|
||||
|
||||
import "github.com/yetone/magpie/internal/rosetta"
|
||||
import (
|
||||
"github.com/yetone/magpie/internal/rosetta"
|
||||
"github.com/yetone/magpie/internal/winarm"
|
||||
)
|
||||
|
||||
// translated says magpie runs under Rosetta: an Intel build on Apple
|
||||
// silicon. Tests replace it.
|
||||
var translated = rosetta.Translated
|
||||
|
||||
// emulated says magpie runs under Windows on Arm's x64 emulation: an x64
|
||||
// build on an Arm64 computer. Tests replace it.
|
||||
var emulated = winarm.Emulated
|
||||
|
||||
@@ -175,7 +175,18 @@ type candidate struct {
|
||||
// A CPU without what pf-serve is built for runs pf-serve-base, on the
|
||||
// CPU alone: pf-serve-vulkan is built like pf-serve, and would end the
|
||||
// same way.
|
||||
//
|
||||
// On Windows on Arm pf-serve runs emulated (onArmWindows): on the CPU,
|
||||
// since the x64 pf-serve-vulkan has no x64 Vulkan driver to load there,
|
||||
// pf-serve and then pf-serve-base, for an emulation without AVX2.
|
||||
func candidates(cpu bool) []candidate {
|
||||
if onArmWindows() {
|
||||
out := []candidate{{exe("pf-serve"), true}}
|
||||
if _, err := os.Stat(exe("pf-serve-base")); err == nil {
|
||||
out = append(out, candidate{exe("pf-serve-base"), true})
|
||||
}
|
||||
return out
|
||||
}
|
||||
if !fullX86() {
|
||||
if _, err := os.Stat(exe("pf-serve-base")); err == nil {
|
||||
return []candidate{{exe("pf-serve-base"), true}}
|
||||
|
||||
@@ -18,9 +18,10 @@ import (
|
||||
// not.
|
||||
func onSystem(t *testing.T, sys, arch string, tr bool) {
|
||||
t.Helper()
|
||||
wasOS, wasArch, wasTr := goos, goarch, translated
|
||||
t.Cleanup(func() { goos, goarch, translated = wasOS, wasArch, wasTr })
|
||||
wasOS, wasArch, wasTr, wasEm := goos, goarch, translated, emulated
|
||||
t.Cleanup(func() { goos, goarch, translated, emulated = wasOS, wasArch, wasTr, wasEm })
|
||||
goos, goarch, translated = sys, arch, func() bool { return tr }
|
||||
emulated = func() bool { return false }
|
||||
}
|
||||
|
||||
// An Intel magpie under Rosetta updates to Apple silicon's build, the app
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/rosetta"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/source"
|
||||
"github.com/yetone/magpie/internal/winarm"
|
||||
)
|
||||
|
||||
// Site is magpie's home; its /api/latest is the update feed.
|
||||
@@ -304,11 +305,13 @@ func parse(v string) *semver {
|
||||
// one.
|
||||
var GUI bool
|
||||
|
||||
// goos and goarch are the system this magpie was built for, and
|
||||
// translated says it runs under Rosetta; tests set them.
|
||||
// goos and goarch are the system this magpie was built for, translated
|
||||
// says it runs under Rosetta, and emulated under Windows on Arm's x64
|
||||
// emulation; tests set them.
|
||||
var (
|
||||
goos, goarch = runtime.GOOS, runtime.GOARCH
|
||||
translated = rosetta.Translated
|
||||
emulated = winarm.Emulated
|
||||
)
|
||||
|
||||
// arch is the architecture an update installs: this build's, but Apple
|
||||
@@ -318,8 +321,14 @@ var (
|
||||
// fetched the Intel build again. Installing Apple silicon's is the same
|
||||
// swap: the zip's magpie.app is renamed over the bundle, signed by the
|
||||
// same team (sameSigner), and the bare binary is renamed over itself.
|
||||
//
|
||||
// The same on Windows: an x64 magpie on an Arm64 computer, emulated,
|
||||
// updates to the arm64 exe (@EV_John_Liu on X, "magpie是转译的"). The swap
|
||||
// is the x64 one: canStart starts the download, which runs natively there,
|
||||
// the running exe is moved aside and the arm64 one renamed in under its
|
||||
// name, and magpie.com is written again from the new app's own launcher.
|
||||
func arch() string {
|
||||
if goos == "darwin" && goarch == "amd64" && translated() {
|
||||
if goarch == "amd64" && (goos == "darwin" && translated() || goos == "windows" && emulated()) {
|
||||
return "arm64"
|
||||
}
|
||||
return goarch
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package update
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// onWindows runs the test as a Windows magpie built for arch, under Windows
|
||||
// on Arm's x64 emulation or not.
|
||||
func onWindows(t *testing.T, arch string, em bool) {
|
||||
t.Helper()
|
||||
onSystem(t, "windows", arch, false)
|
||||
emulated = func() bool { return em }
|
||||
}
|
||||
|
||||
// An x64 magpie emulated on Windows on Arm updates to the arm64 exe, the
|
||||
// app and the terminal build alike (@EV_John_Liu on X); an x64 Windows
|
||||
// computer, and an arm64 build, update to their own. Emulation is
|
||||
// Windows' alone: a Mac or Linux magpie asked about it is unchanged.
|
||||
func TestWindowsOnArmUpdatesToArm64(t *testing.T) {
|
||||
was := GUI
|
||||
t.Cleanup(func() { GUI = was })
|
||||
for _, c := range []struct {
|
||||
os, arch string
|
||||
em, gui bool
|
||||
bin string
|
||||
}{
|
||||
{"windows", "amd64", true, true, "magpie-windows-arm64.exe"},
|
||||
{"windows", "amd64", true, false, "magpie-cli-windows-arm64.exe"},
|
||||
{"windows", "amd64", false, true, "magpie-windows-amd64.exe"},
|
||||
{"windows", "amd64", false, false, "magpie-cli-windows-amd64.exe"},
|
||||
{"windows", "arm64", false, true, "magpie-windows-arm64.exe"},
|
||||
{"darwin", "amd64", true, false, "magpie-cli-darwin-amd64"},
|
||||
{"linux", "amd64", true, true, "magpie-linux-amd64"},
|
||||
} {
|
||||
onSystem(t, c.os, c.arch, false)
|
||||
emulated = func() bool { return c.em }
|
||||
GUI = c.gui
|
||||
if got := BinaryAsset(); got != c.bin {
|
||||
t.Errorf("%s/%s emulated=%v gui=%v: BinaryAsset = %s, want %s", c.os, c.arch, c.em, c.gui, got, c.bin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Emulated, the update downloads the arm64 exe, not the x64 one, and swaps
|
||||
// it in for the running x64 exe as any update is: under the same name, the
|
||||
// old one moved aside.
|
||||
func TestWindowsOnArmInstallsArm64Exe(t *testing.T) {
|
||||
was := GUI
|
||||
t.Cleanup(func() { GUI = was })
|
||||
GUI = true
|
||||
onWindows(t, "amd64", true)
|
||||
wasStart := canStart
|
||||
t.Cleanup(func() { canStart = wasStart })
|
||||
canStart = func(string) error { return nil }
|
||||
|
||||
bodies := map[string]string{
|
||||
"magpie-windows-amd64.exe": "2.0 for x64",
|
||||
"magpie-windows-arm64.exe": "2.0 for arm64",
|
||||
}
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(bodies[strings.TrimPrefix(r.URL.Path, "/")]))
|
||||
}))
|
||||
defer srv.Close()
|
||||
assets := map[string]Asset{}
|
||||
for name, body := range bodies {
|
||||
sum := sha256.Sum256([]byte(body))
|
||||
assets[name] = Asset{URL: srv.URL + "/" + name, Size: int64(len(body)), SHA256: hex.EncodeToString(sum[:])}
|
||||
}
|
||||
rel := &Release{Version: "2.0", Assets: assets}
|
||||
|
||||
exe := filepath.Join(t.TempDir(), "magpie.exe")
|
||||
if err := os.WriteFile(exe, []byte("1.0 for x64"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
staged, err := stageBinaryFor(context.Background(), rel.Assets[BinaryAsset()], exe)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := InstallBinaryAside(staged, exe); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, _ := os.ReadFile(exe); string(got) != "2.0 for arm64" {
|
||||
t.Fatalf("magpie.exe is %q, want the arm64 build", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Package winarm says whether magpie runs under Windows on Arm's x64
|
||||
// emulation: an x64 build on an Arm64 computer. Such a magpie works, but
|
||||
// its own heavy code (the local masking model) runs translated, and every
|
||||
// update fetched the x64 build again (@EV_John_Liu on X: "magpie是转译的").
|
||||
// It is Rosetta's counterpart (internal/rosetta), kept apart because what
|
||||
// magpie tells the user differs.
|
||||
package winarm
|
||||
|
||||
import "debug/pe"
|
||||
|
||||
// emulated says a process of goarch runs emulated on a computer whose
|
||||
// native machine is native, as IsWow64Process2 said, or failed to (err).
|
||||
// A failed call (Windows before 10 1511, which has no IsWow64Process2) is
|
||||
// not translated, and so is any build but x64: an x86 magpie isn't built.
|
||||
func emulated(goarch string, native uint16, err error) bool {
|
||||
return err == nil && goarch == "amd64" && native == pe.IMAGE_FILE_MACHINE_ARM64
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build !windows
|
||||
|
||||
package winarm
|
||||
|
||||
// Emulated says this process runs under Windows on Arm's x64 emulation:
|
||||
// never off Windows.
|
||||
func Emulated() bool { return false }
|
||||
@@ -0,0 +1,36 @@
|
||||
package winarm
|
||||
|
||||
import (
|
||||
"debug/pe"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Only an x64 build whose computer is Arm64 is emulated; a failed
|
||||
// IsWow64Process2 is native.
|
||||
func TestEmulated(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
arch string
|
||||
native uint16
|
||||
err error
|
||||
want bool
|
||||
}{
|
||||
{"amd64", pe.IMAGE_FILE_MACHINE_ARM64, nil, true},
|
||||
{"amd64", pe.IMAGE_FILE_MACHINE_AMD64, nil, false},
|
||||
{"amd64", pe.IMAGE_FILE_MACHINE_ARM64, errors.New("procedure not found"), false},
|
||||
{"arm64", pe.IMAGE_FILE_MACHINE_ARM64, nil, false},
|
||||
{"386", pe.IMAGE_FILE_MACHINE_ARM64, nil, false},
|
||||
} {
|
||||
if got := emulated(c.arch, c.native, c.err); got != c.want {
|
||||
t.Errorf("emulated(%s, %#x, %v) = %v, want %v", c.arch, c.native, c.err, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Off Windows, and on an x64 Windows computer, this process isn't
|
||||
// emulated: the CI and test machines are one or the other.
|
||||
func TestNotEmulatedHere(t *testing.T) {
|
||||
if Emulated() {
|
||||
t.Fatal("Emulated() on a test machine that isn't Windows on Arm")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package winarm
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
// Emulated says this process is an x64 magpie under Windows on Arm's
|
||||
// emulation. IsWow64Process2 answers an x64 process there with
|
||||
// processMachine IMAGE_FILE_MACHINE_UNKNOWN (x64 emulation isn't WOW64)
|
||||
// and nativeMachine IMAGE_FILE_MACHINE_ARM64.
|
||||
var Emulated = sync.OnceValue(func() bool {
|
||||
var proc, native uint16
|
||||
err := windows.IsWow64Process2(windows.CurrentProcess(), &proc, &native)
|
||||
return emulated(runtime.GOARCH, native, err)
|
||||
})
|
||||
Reference in New Issue
Block a user