MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / macho_build_version

Function macho_build_version

cranelift/object/src/backend.rs:176–236  ·  view source on GitHub ↗

See the following for details:

(triple: &Triple)

Source from the content-addressed store, hash-verified

174/// See the following for details:
175/// <https://github.com/rust-lang/rust/blob/1.95.0/compiler/rustc_codegen_ssa/src/back/metadata.rs#L408-L425>
176fn macho_build_version(triple: &Triple) -> Option<object::write::MachOBuildVersion> {
177 use target_lexicon::{DeploymentTarget, OperatingSystem::*};
178
179 fn pack_version(v: DeploymentTarget) -> u32 {
180 let (major, minor, patch) = (v.major as u32, v.minor as u32, v.patch as u32);
181 (major << 16) | (minor << 8) | patch
182 }
183
184 match triple.operating_system {
185 Darwin(v) | MacOSX(v) | IOS(v) | TvOS(v) | VisionOS(v) | WatchOS(v) | XROS(v) => {
186 use object::macho::*;
187 use target_lexicon::Environment::*;
188 // Same as https://github.com/rust-lang/rust/blob/1.95.0/compiler/rustc_codegen_ssa/src/back/apple.rs#L36-L50.
189 //
190 // TODO(madsmtm): Properly support simulator after
191 // https://github.com/bytecodealliance/target-lexicon/pull/130
192 let platform = match (triple.operating_system, triple.environment) {
193 // Sometimes the target is macOS but the environment is Darwin,
194 // and sometimes it's the other way around. Support both.
195 (Darwin(_), _) => PLATFORM_MACOS,
196 (MacOSX(_), _) => PLATFORM_MACOS,
197 (_, Macabi) => PLATFORM_MACCATALYST,
198 (IOS(_), Sim) => PLATFORM_IOSSIMULATOR,
199 (IOS(_), _) => PLATFORM_IOS,
200 (TvOS(_), Sim) => PLATFORM_TVOSSIMULATOR,
201 (TvOS(_), _) => PLATFORM_TVOS,
202 (VisionOS(_) | XROS(_), Sim) => PLATFORM_XROSSIMULATOR,
203 (VisionOS(_) | XROS(_), _) => PLATFORM_XROS,
204 (WatchOS(_), Sim) => PLATFORM_WATCHOSSIMULATOR,
205 (WatchOS(_), _) => PLATFORM_WATCHOS,
206 _ => {
207 warn!("unsupported OS/environment: {triple}");
208 0
209 }
210 };
211
212 let mut build_version = object::write::MachOBuildVersion::default();
213 build_version.platform = platform;
214
215 build_version.minos = if let Some(v) = v {
216 pack_version(v)
217 } else {
218 // The `minos` in object files is useful for diagnostics, as
219 // it tells the linker whether the file supports a given OS -
220 // if the `minos` is higher than what you're linking against,
221 // that's a signal that something has gone wrong.
222 //
223 // Using `0.0.0` here should be fine if we don't have the data
224 // available.
225 0
226 };
227
228 // Setting a 0 SDK version is fine, it's only relevant for the
229 // final linked binary.
230 build_version.sdk = 0;
231
232 Some(build_version)
233 }

Callers 1

newMethod · 0.85

Calls 1

pack_versionFunction · 0.85

Tested by

no test coverage detected