| 1 |
# Copyright 2016 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
require 'rbconfig' |
| 16 |
|
| 17 |
# This is based on http://stackoverflow.com/a/171011/159388 by Aaron Hinni |
| 18 |
|
| 19 |
module PLATFORM |
| 20 |
def PLATFORM.os_name |
| 21 |
case RbConfig::CONFIG['host_os'] |
| 22 |
when /cygwin|mswin|mingw|bccwin|wince|emx/ |
| 23 |
'windows' |
| 24 |
when /darwin/ |
| 25 |
'macos' |
| 26 |
else |
| 27 |
'linux' |
| 28 |
end |
| 29 |
end |
| 30 |
|
| 31 |
def PLATFORM.architecture |
| 32 |
host_cpu = RbConfig::CONFIG['host_cpu'] |
| 33 |
|
| 34 |
# When we're on arm in macOS, we can rely on Rosetta and use the x86_64 binary |
| 35 |
return 'x86_64' if RbConfig::CONFIG['host_os'] =~ /darwin/ && host_cpu =~ /arm/ |
| 36 |
|
| 37 |
case host_cpu |
| 38 |
when /x86_64/ |
| 39 |
'x86_64' |
| 40 |
else |
| 41 |
'x86' |
| 42 |
end |
| 43 |
end |
| 44 |
end |