fix --arch flag to fall back to emulation when native image unavailable, always infer hardware requirement for arch

This commit is contained in:
Matt Hill
2026-01-31 10:16:55 -07:00
parent 4f84073cb5
commit 0583aa455a
3 changed files with 33 additions and 23 deletions

View File

@@ -686,7 +686,7 @@ pub async fn pack(ctx: CliContext, params: PackParams) -> Result<(), Error> {
let manifest = s9pk.as_manifest_mut(); let manifest = s9pk.as_manifest_mut();
manifest.git_hash = Some(GitHash::from_path(params.path()).await?); manifest.git_hash = Some(GitHash::from_path(params.path()).await?);
if !params.arch.is_empty() { if !params.arch.is_empty() {
let arches = match manifest.hardware_requirements.arch.take() { let arches: BTreeSet<InternedString> = match manifest.hardware_requirements.arch.take() {
Some(a) => params Some(a) => params
.arch .arch
.iter() .iter()
@@ -695,10 +695,26 @@ pub async fn pack(ctx: CliContext, params: PackParams) -> Result<(), Error> {
.collect(), .collect(),
None => params.arch.iter().cloned().collect(), None => params.arch.iter().cloned().collect(),
}; };
manifest if arches.is_empty() {
.images return Err(Error::new(
.values_mut() eyre!(
.for_each(|c| c.arch = c.arch.intersection(&arches).cloned().collect()); "none of the requested architectures ({:?}) are supported by this package",
params.arch
),
ErrorKind::InvalidRequest,
));
}
manifest.images.values_mut().for_each(|c| {
let mut to_load = BTreeSet::new();
for arch in &arches {
if c.arch.contains(arch) {
to_load.insert(arch.clone());
} else if let Some(ref emulate_as) = c.emulate_missing_as {
to_load.insert(emulate_as.clone());
}
}
c.arch = to_load;
});
manifest.hardware_requirements.arch = Some(arches); manifest.hardware_requirements.arch = Some(arches);
} }

View File

@@ -132,7 +132,6 @@ export type SDKManifest = {
* `pattern` refers to a regular expression that at least one device of the specified class must match * `pattern` refers to a regular expression that at least one device of the specified class must match
* `patternDescription` is what will be displayed to the user about what kind of device is required * `patternDescription` is what will be displayed to the user about what kind of device is required
* @property {number} ram - Minimum RAM requirement (in megabytes MB) * @property {number} ram - Minimum RAM requirement (in megabytes MB)
* @property {string[]} arch - List of supported arches
* @example * @example
* ``` * ```
hardwareRequirements: { hardwareRequirements: {
@@ -141,14 +140,12 @@ export type SDKManifest = {
{ class: 'processor', pattern: 'i[3579]-10[0-9]{3}U CPU', patternDescription: 'A 10th Generation Intel i-Series processor' }, { class: 'processor', pattern: 'i[3579]-10[0-9]{3}U CPU', patternDescription: 'A 10th Generation Intel i-Series processor' },
], ],
ram: 8192, ram: 8192,
arch: ['x86-64'],
}, },
* ``` * ```
*/ */
readonly hardwareRequirements?: { readonly hardwareRequirements?: {
readonly device?: T.DeviceFilter[] readonly device?: T.DeviceFilter[]
readonly ram?: number | null readonly ram?: number | null
readonly arch?: string[] | null
} }
/** /**

View File

@@ -75,21 +75,18 @@ export function buildManifest<
hardwareRequirements: { hardwareRequirements: {
device: manifest.hardwareRequirements?.device || [], device: manifest.hardwareRequirements?.device || [],
ram: manifest.hardwareRequirements?.ram || null, ram: manifest.hardwareRequirements?.ram || null,
arch: arch: Object.values(images).reduce(
manifest.hardwareRequirements?.arch === undefined (arch, inputSpec) => {
? Object.values(images).reduce( if (inputSpec.emulateMissingAs) {
(arch, inputSpec) => { return arch
if (inputSpec.emulateMissingAs) { }
return arch if (arch === null) {
} return inputSpec.arch
if (arch === null) { }
return inputSpec.arch return arch.filter((a) => inputSpec.arch.includes(a))
} },
return arch.filter((a) => inputSpec.arch.includes(a)) null as string[] | null,
}, ),
null as string[] | null,
)
: manifest.hardwareRequirements?.arch,
}, },
hardwareAcceleration: manifest.hardwareAcceleration ?? false, hardwareAcceleration: manifest.hardwareAcceleration ?? false,
} }