Skip to content

Commit

Permalink
Default to ARM64 when running on Arm hosts
Browse files Browse the repository at this point in the history
If the function architecture isn't specified and we're running on an Arm
platform assume we should be trying to run the function for ARM64

Fixes #4708
  • Loading branch information
AGSaidi committed Feb 17, 2023
1 parent eb8c117 commit ec7ed7b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions samcli/lib/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import posixpath
from collections import namedtuple
from platform import machine
from typing import Any, Set, NamedTuple, Optional, List, Dict, Tuple, Union, cast, Iterator, TYPE_CHECKING

from samcli.commands.local.cli_common.user_exceptions import (
Expand All @@ -20,7 +21,7 @@
SAM_METADATA_SKIP_BUILD_KEY,
SAM_RESOURCE_ID_KEY,
)
from samcli.lib.utils.architecture import X86_64
from samcli.lib.utils.architecture import X86_64, ARM64

if TYPE_CHECKING: # pragma: no cover
# avoid circular import, https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING
Expand Down Expand Up @@ -129,7 +130,7 @@ def architecture(self) -> str:
If the architectures value is invalid
"""
if not self.architectures:
return X86_64
return ARM64 if machine() in ("arm64", "aarch64") else X86_64

arch_list = cast(list, self.architectures)
if len(arch_list) != 1:
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/commands/local/lib/test_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import posixpath
from platform import machine
from unittest import TestCase
from unittest.mock import MagicMock, Mock, patch

Expand Down Expand Up @@ -300,7 +301,7 @@ def setUp(self) -> None:
@parameterized.expand(
[
([ARM64], ARM64),
([], X86_64),
([], ARM64 if machine() in ("arm64", "aarch64") else X86_64),
([X86_64], X86_64),
]
)
Expand Down

0 comments on commit ec7ed7b

Please sign in to comment.