@@ -13,8 +13,8 @@ use crate::fluent_generated;
1313use crate :: session_diagnostics:: {
1414 AsNeededCompatibility , BundleNeedsStatic , EmptyLinkName , ImportNameTypeRaw , ImportNameTypeX86 ,
1515 IncompatibleWasmLink , InvalidLinkModifier , LinkFrameworkApple , LinkOrdinalOutOfRange ,
16- LinkRequiresName , MultipleModifiers , NullOnLinkSection , RawDylibNoNul , RawDylibOnlyWindows ,
17- WholeArchiveNeedsStatic ,
16+ LinkRequiresName , MultipleModifiers , NullOnLinkSection , RawDylibMachoUseVerbatim ,
17+ RawDylibNoNul , RawDylibOnlyWindows , WholeArchiveNeedsStatic ,
1818} ;
1919
2020pub ( crate ) struct LinkNameParser ;
@@ -218,6 +218,17 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
218218 cx. emit_err ( RawDylibNoNul { span : name_span } ) ;
219219 }
220220
221+ if sess. target . binary_format == BinaryFormat :: MachO
222+ && kind == Some ( NativeLibKind :: RawDylib )
223+ && verbatim != Some ( true )
224+ {
225+ // It is possible for us to emit a non-absolute path like `libSystem.dylib` in the
226+ // binary and have that work as well, though it's unclear what the use-case of that
227+ // would be, and it might lead to people accidentally specifying too "lax" linking.
228+ // So let's disallow it for now.
229+ cx. emit_err ( RawDylibMachoUseVerbatim { span : cx. attr_span } ) ;
230+ }
231+
221232 result = Some ( LinkEntry {
222233 span : cx. attr_span ,
223234 kind : kind. unwrap_or ( NativeLibKind :: Unspecified ) ,
@@ -286,22 +297,42 @@ impl LinkParser {
286297 NativeLibKind :: Framework { as_needed : None }
287298 }
288299 sym:: raw_dash_dylib => {
289- if sess. target . is_like_windows {
290- // raw-dylib is stable and working on Windows
291- } else if sess. target . binary_format == BinaryFormat :: Elf && features. raw_dylib_elf ( )
292- {
293- // raw-dylib is unstable on ELF, but the user opted in
294- } else if sess. target . binary_format == BinaryFormat :: Elf && sess. is_nightly_build ( )
295- {
296- feature_err (
297- sess,
298- sym:: raw_dylib_elf,
299- nv. value_span ,
300- fluent_generated:: attr_parsing_raw_dylib_elf_unstable,
301- )
302- . emit ( ) ;
303- } else {
304- cx. emit_err ( RawDylibOnlyWindows { span : nv. value_span } ) ;
300+ match sess. target . binary_format {
301+ _ if sess. target . is_like_windows => {
302+ // raw-dylib is stable and working on Windows
303+ }
304+
305+ BinaryFormat :: Elf if features. raw_dylib_elf ( ) => {
306+ // raw-dylib is unstable on ELF, but the user opted in
307+ }
308+ BinaryFormat :: Elf if sess. is_nightly_build ( ) => {
309+ // Incomplete, so don't recommend if not nightly.
310+ feature_err (
311+ sess,
312+ sym:: raw_dylib_elf,
313+ nv. value_span ,
314+ fluent_generated:: attr_parsing_raw_dylib_elf_unstable,
315+ )
316+ . emit ( ) ;
317+ }
318+
319+ BinaryFormat :: MachO if features. raw_dylib_macho ( ) => {
320+ // raw-dylib is unstable on Mach-O, but the user opted in
321+ }
322+ BinaryFormat :: MachO if sess. is_nightly_build ( ) => {
323+ // Incomplete, so don't recommend if not nightly.
324+ feature_err (
325+ sess,
326+ sym:: raw_dylib_macho,
327+ nv. value_span ,
328+ fluent_generated:: attr_parsing_raw_dylib_macho_unstable,
329+ )
330+ . emit ( ) ;
331+ }
332+
333+ _ => {
334+ cx. emit_err ( RawDylibOnlyWindows { span : nv. value_span } ) ;
335+ }
305336 }
306337
307338 NativeLibKind :: RawDylib
0 commit comments