Skip to content

A way to specify "macOS universal" tool host in index.json #1917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
carlosperate opened this issue Oct 11, 2022 · 3 comments
Closed
2 of 3 tasks

A way to specify "macOS universal" tool host in index.json #1917

carlosperate opened this issue Oct 11, 2022 · 3 comments
Assignees
Labels
type: enhancement Proposed improvement

Comments

@carlosperate
Copy link

carlosperate commented Oct 11, 2022

Describe the request

When building an Arduino Core and packaging tools, it looks like there isn't a way to specify a macOS universal "host".

Having a look in https://downloads.arduino.cc/packages/package_index.json I'm not 100% sure what's the right name for the arm64 macOS host, as I can't find any entry there. But based on this test file I believe it's arm64-apple-darwin?:

{&Flavor{OS: "arm64-apple-darwin"}, []*os{darwinArm64}, []*os{darwinArm64}},

Describe the current behavior

We can have an entry for arm64-apple-darwin and another for x86_64-apple-darwin, which would be pretty much a copy/paste of the other with a different "host" name.

Arduino CLI version

N/A

Operating system

macOS

Operating system version

N/A

Additional context

This is not extrictly neccesary, as having multiple entries works, so I guess it's more like a "nice to have".

Issue checklist

  • I searched for previous requests in the issue tracker
  • I verified the feature was still missing when using the nightly build
  • My request contains all necessary details
@carlosperate carlosperate added the type: enhancement Proposed improvement label Oct 11, 2022
@per1234
Copy link
Contributor

per1234 commented Oct 12, 2022

Hi @carlosperate. You can see the code for selecting the appropriate tool flavor here:

var (
regexpLinuxArm = regexp.MustCompile("arm.*-linux-gnueabihf")
regexpLinuxArm64 = regexp.MustCompile("(aarch64|arm64)-linux-gnu")
regexpLinux64 = regexp.MustCompile("x86_64-.*linux-gnu")
regexpLinux32 = regexp.MustCompile("i[3456]86-.*linux-gnu")
regexpWindows32 = regexp.MustCompile("i[3456]86-.*(mingw32|cygwin)")
regexpWindows64 = regexp.MustCompile("(amd64|x86_64)-.*(mingw32|cygwin)")
regexpMac64 = regexp.MustCompile("x86_64-apple-darwin.*")
regexpMac32 = regexp.MustCompile("i[3456]86-apple-darwin.*")
regexpMacArm64 = regexp.MustCompile("arm64-apple-darwin.*")
regexpFreeBSDArm = regexp.MustCompile("arm.*-freebsd[0-9]*")
regexpFreeBSD32 = regexp.MustCompile("i?[3456]86-freebsd[0-9]*")
regexpFreeBSD64 = regexp.MustCompile("amd64-freebsd[0-9]*")
)
func (f *Flavor) isExactMatchWith(osName, osArch string) bool {
if f.OS == "all" {
return true
}
switch osName + "," + osArch {
case "linux,arm", "linux,armbe":
return regexpLinuxArm.MatchString(f.OS)
case "linux,arm64":
return regexpLinuxArm64.MatchString(f.OS)
case "linux,amd64":
return regexpLinux64.MatchString(f.OS)
case "linux,386":
return regexpLinux32.MatchString(f.OS)
case "windows,386":
return regexpWindows32.MatchString(f.OS)
case "windows,amd64":
return regexpWindows64.MatchString(f.OS)
case "darwin,arm64":
return regexpMacArm64.MatchString(f.OS)
case "darwin,amd64":
return regexpMac64.MatchString(f.OS)
case "darwin,386":
return regexpMac32.MatchString(f.OS)
case "freebsd,arm":
return regexpFreeBSDArm.MatchString(f.OS)
case "freebsd,386":
return regexpFreeBSD32.MatchString(f.OS)
case "freebsd,amd64":
return regexpFreeBSD64.MatchString(f.OS)
}
return false
}
func (f *Flavor) isCompatibleWith(osName, osArch string) (bool, int) {
if f.isExactMatchWith(osName, osArch) {
return true, 1000
}
switch osName + "," + osArch {
case "windows,amd64":
return regexpWindows32.MatchString(f.OS), 10
case "darwin,amd64":
return regexpMac32.MatchString(f.OS), 10
case "darwin,arm64":
// Compatibility guaranteed through Rosetta emulation
if regexpMac64.MatchString(f.OS) {
// Prefer amd64 version if available
return true, 20
}
return regexpMac32.MatchString(f.OS), 10
}
return false, 0
}
// GetCompatibleFlavour returns the downloadable resource compatible with the running O.S.
func (tr *ToolRelease) GetCompatibleFlavour() *resources.DownloadResource {
return tr.GetFlavourCompatibleWith(runtime.GOOS, runtime.GOARCH)
}
// GetFlavourCompatibleWith returns the downloadable resource compatible with the specified O.S.
func (tr *ToolRelease) GetFlavourCompatibleWith(osName, osArch string) *resources.DownloadResource {
var resource *resources.DownloadResource
priority := -1
for _, flavour := range tr.Flavors {
if comp, p := flavour.isCompatibleWith(osName, osArch); comp && p > priority {
resource = flavour.Resource
priority = p
}
}
return resource
}

So a host value matching the regular expression i[3456]86-apple-darwin.* will cause the tool to be used on:

  • macOS x86
  • macOS x86-64
  • macOS ARM

A host value matching the regular expression x86_64-apple-darwin.* will cause the tool to be used on:

  • macOS x86-64
  • macOS ARM

I aspired to document the supported values of packages[*].tools[*].systems[*].host at one time, but never managed to figure out how to do it.

@cmaglie
Copy link
Member

cmaglie commented Apr 28, 2023

AFAIU, this is a documentation problem? can we close this in favor of #2004?

@cmaglie cmaglie self-assigned this Apr 28, 2023
@carlosperate
Copy link
Author

Yes, I think this can be covered as a documentation update as part of #2004.

Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

3 participants