[PATCH] D51910: [Modules] Add platform feature to requires clause
Bruno Cardoso Lopes via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 10 21:49:03 PDT 2018
bruno created this revision.
bruno added reviewers: rsmith, v.g.vassilev, aprantl.
Herald added subscribers: dexonsmith, srhines.
Allows module map writers to add build requirements based on platform/os. Useful when target features and language dialects aren't enough to conditionalize building a module. Among other things, it also makes it more convenient for modules with the same name but different set of submodules to be described in the same module map.
rdar://problem/43909745
Repository:
rC Clang
https://reviews.llvm.org/D51910
Files:
docs/Modules.rst
lib/Basic/Module.cpp
test/Modules/target-platform-features.m
Index: test/Modules/target-platform-features.m
===================================================================
--- /dev/null
+++ test/Modules/target-platform-features.m
@@ -0,0 +1,33 @@
+// Clear and create directories
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: mkdir %t/cache
+// RUN: mkdir %t/Inputs
+
+// Build module map file
+// RUN: echo "module RequiresMacOS {" >> %t/Inputs/module.map
+// RUN: echo " requires macos" >> %t/Inputs/module.map
+// RUN: echo "}" >> %t/Inputs/module.map
+// RUN: echo "module RequiresNotiOS {" >> %t/Inputs/module.map
+// RUN: echo " requires !ios" >> %t/Inputs/module.map
+// RUN: echo "}" >> %t/Inputs/module.map
+// RUN: echo "module RequiresMain {" >> %t/Inputs/module.map
+// RUN: echo " module SubRequiresNotiOS {" >> %t/Inputs/module.map
+// RUN: echo " requires !ios" >> %t/Inputs/module.map
+// RUN: echo " }" >> %t/Inputs/module.map
+// RUN: echo "}" >> %t/Inputs/module.map
+
+// RUN: %clang_cc1 -triple=x86_64-apple-macosx10.6 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/Inputs -verify %s -fblocks -fobjc-arc
+// expected-no-diagnostics
+
+// RUN: not %clang_cc1 -triple=arm64-apple-ios -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache -x objective-c -I%t/Inputs %s -fblocks -fobjc-arc 2> %t.notios
+// RUN: FileCheck %s -check-prefix=CHECK-IOS < %t.notios
+
+// CHECK-IOS: module 'RequiresMacOS' requires feature 'macos'
+ at import RequiresMacOS;
+// CHECK-IOS: module 'RequiresNotiOS' is incompatible with feature 'ios'
+ at import RequiresNotiOS;
+
+// We should never get errors for submodules that don't match
+// CHECK-IOS-NOT: module 'RequiresMain'
+ at import RequiresMain;
Index: lib/Basic/Module.cpp
===================================================================
--- lib/Basic/Module.cpp
+++ lib/Basic/Module.cpp
@@ -93,7 +93,8 @@
.Case("opencl", LangOpts.OpenCL)
.Case("tls", Target.isTLSSupported())
.Case("zvector", LangOpts.ZVector)
- .Default(Target.hasFeature(Feature));
+ .Default(Target.hasFeature(Feature) ||
+ Target.getPlatformName() == Feature);
if (!HasFeature)
HasFeature = std::find(LangOpts.ModuleFeatures.begin(),
LangOpts.ModuleFeatures.end(),
Index: docs/Modules.rst
===================================================================
--- docs/Modules.rst
+++ docs/Modules.rst
@@ -466,6 +466,8 @@
*target feature*
A specific target feature (e.g., ``sse4``, ``avx``, ``neon``) is available.
+*platform variant*
+ A specific os/platform variant (e.g. ``ios``, ``macos``, ``android``, ``win32``, ``linux``, etc) is available.
**Example:** The ``std`` module can be extended to also include C++ and C++11 headers using a *requires-declaration*:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51910.164802.patch
Type: text/x-patch
Size: 2998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180911/d1945641/attachment-0001.bin>
More information about the cfe-commits
mailing list