Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/105067/?format=api
http://patches.dpdk.org/api/patches/105067/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/20211210145330.108256-1-bruce.richardson@intel.com/", "project": { "id": 1, "url": "http://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<20211210145330.108256-1-bruce.richardson@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/20211210145330.108256-1-bruce.richardson@intel.com", "date": "2021-12-10T14:53:30", "name": "build/eal: add OS defines for C conditional checks", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "763d03d496a8c6afa1afe56df2508a9cc0c844e0", "submitter": { "id": 20, "url": "http://patches.dpdk.org/api/people/20/?format=api", "name": "Bruce Richardson", "email": "bruce.richardson@intel.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/20211210145330.108256-1-bruce.richardson@intel.com/mbox/", "series": [ { "id": 20912, "url": "http://patches.dpdk.org/api/series/20912/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=20912", "date": "2021-12-10T14:53:30", "name": "build/eal: add OS defines for C conditional checks", "version": 1, "mbox": "http://patches.dpdk.org/series/20912/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/105067/comments/", "check": "success", "checks": "http://patches.dpdk.org/api/patches/105067/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@inbox.dpdk.org", "Delivered-To": "patchwork@inbox.dpdk.org", "Received": [ "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 94CF0A0093;\n\tFri, 10 Dec 2021 15:53:39 +0100 (CET)", "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 24BA54014F;\n\tFri, 10 Dec 2021 15:53:39 +0100 (CET)", "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n by mails.dpdk.org (Postfix) with ESMTP id 51A2740041\n for <dev@dpdk.org>; Fri, 10 Dec 2021 15:53:38 +0100 (CET)", "from fmsmga007.fm.intel.com ([10.253.24.52])\n by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 10 Dec 2021 06:53:37 -0800", "from silpixa00399126.ir.intel.com ([10.237.223.86])\n by fmsmga007.fm.intel.com with ESMTP; 10 Dec 2021 06:53:36 -0800" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=simple/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1639148018; x=1670684018;\n h=from:to:cc:subject:date:message-id:mime-version:\n content-transfer-encoding;\n bh=FlcE3ti5931VhBP9WDz9ydBg4DkWugpfZ1hbnPbzVVU=;\n b=Vop7m4yVh349bto5D4mTRHM/GLMLBNClEHrDBZj2c6LL0m+DN0DK+lWH\n XzELHNylrziXwdXNTGZTOVLrhHdhUJMJd13ow9WJRAadGepbiHptO5tb3\n Nn7GokJqZG9luDPt6mwweYfCBG69ktY/fg4PRO2IItD1IXEJlCJf81aJc\n F2u5J1lfKLUxHG2XYdJvV3ydFvd0pAfHT47DHKyl6IKmmst00f5luPPXC\n KlinDa8RJgN5HI4ZsbfEwwLty+4k9NJxGDjO7yJXOP6lixJhFogk0/n93\n yFaAAozI/7xTx+ZcL1Go9Wis/RmUbjyyYOympS4xOy90j0NuIiEpoIHPF Q==;", "X-IronPort-AV": [ "E=McAfee;i=\"6200,9189,10193\"; a=\"237092418\"", "E=Sophos;i=\"5.88,195,1635231600\"; d=\"scan'208\";a=\"237092418\"", "E=Sophos;i=\"5.88,195,1635231600\"; d=\"scan'208\";a=\"517299285\"" ], "X-ExtLoop1": "1", "From": "Bruce Richardson <bruce.richardson@intel.com>", "To": "dev@dpdk.org", "Cc": "dmitry.kozliuk@gmail.com, aconole@redhat.com,\n Bruce Richardson <bruce.richardson@intel.com>", "Subject": "[PATCH] build/eal: add OS defines for C conditional checks", "Date": "Fri, 10 Dec 2021 14:53:30 +0000", "Message-Id": "<20211210145330.108256-1-bruce.richardson@intel.com>", "X-Mailer": "git-send-email 2.32.0", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org" }, "content": "Define a set of macros in the build configuration to allow C runtime\ncode to check the current OS environment. This saves the user having to\nuse ifdefs for e.g. disabling particular tests on Windows. See included\ndocumentation changes for usage examples.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\n---\n doc/guides/contributing/coding_style.rst | 42 ++++++++++++++++++++++--\n lib/eal/meson.build | 7 ++++\n 2 files changed, 47 insertions(+), 2 deletions(-)", "diff": "diff --git a/doc/guides/contributing/coding_style.rst b/doc/guides/contributing/coding_style.rst\nindex 0ec37c019b..e52ecb2b60 100644\n--- a/doc/guides/contributing/coding_style.rst\n+++ b/doc/guides/contributing/coding_style.rst\n@@ -136,6 +136,12 @@ For example:\n Conditional Compilation\n ~~~~~~~~~~~~~~~~~~~~~~~\n \n+.. note::\n+\n+ Conditional compilation should be used only when absolutely necessary, as it increases the number of target binaries that need to be built and tested.\n+ See below for details of some utility macros/defines available to allow ifdefs/macros to be replaced by C conditional in some cases.\n+\n+\n * When code is conditionally compiled using ``#ifdef`` or ``#if``, a comment may be added following the matching\n ``#endif`` or ``#else`` to permit the reader to easily discern where conditionally compiled code regions end.\n * This comment should be used only for (subjectively) long regions, regions greater than 20 lines, or where a series of nested ``#ifdef``'s may be confusing to the reader.\n@@ -165,9 +171,41 @@ Conditional Compilation\n /* Or here. */\n #endif /* !COMPAT_43 */\n \n-.. note::\n+Defines to Avoid Conditional Compilation\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+In many cases in DPDK, one wants to optionally compile code based on the target platform,\n+or runtime environment.\n+While this can be done using the conditional compilation directives,\n+e.g. ``#ifdef RTE_EXEC_ENV_LINUX``, present in DPDK for many releases,\n+this can also be done in many cases using regular ``if`` statements and the following defines:\n+\n+* ``RTE_ENV_FREEBSD``, ``RTE_ENV_LINUX``, ``RTE_ENV_WINDOWS`` - these define ids for each operating system environment.\n+* ``RTE_EXEC_ENV`` - this defines the id of the current environment, i.e. one of the items in list above.\n+* ``RTE_EXEC_ENV_IS_FREEBSD``, ``RTE_EXEC_ENV_IS_LINUX``, ``RTE_EXEC_ENV_IS_WINDOWS`` - 0/1 values indicating if the current environment is that specified,\n+ shortcuts for checking e.g. ``RTE_EXEC_ENV == RTE_ENV_WINDOWS``\n+\n+Examples of use:\n+\n+.. code-block:: c\n+\n+ /* report a unit tests as unsupported on Windows */\n+ if (RTE_EXEC_ENV_IS_WINDOWS)\n+ return TEST_SKIPPED;\n+\n+ /* set different default values depending on OS Environment */\n+ switch (RTE_EXEC_ENV) {\n+ case RTE_ENV_FREEBSD:\n+ default = x;\n+ break;\n+ case RTE_ENV_LINUX:\n+ default = y;\n+ break;\n+ case RTE_ENV_WINDOWS:\n+ default = z;\n+ break;\n+ }\n \n- Conditional compilation should be used only when absolutely necessary, as it increases the number of target binaries that need to be built and tested.\n \n C Types\n -------\ndiff --git a/lib/eal/meson.build b/lib/eal/meson.build\nindex 1722924f67..056beb9461 100644\n--- a/lib/eal/meson.build\n+++ b/lib/eal/meson.build\n@@ -10,6 +10,13 @@ if not is_windows\n subdir('unix')\n endif\n \n+exec_envs = {'freebsd': 0, 'linux': 1, 'windows': 2}\n+foreach env, id:exec_envs\n+ dpdk_conf.set('RTE_ENV_' + env.to_upper(), id)\n+ dpdk_conf.set10('RTE_EXEC_ENV_IS_' + env.to_upper(), (exec_env == env))\n+endforeach\n+dpdk_conf.set('RTE_EXEC_ENV', exec_envs[exec_env])\n+\n dpdk_conf.set('RTE_EXEC_ENV_' + exec_env.to_upper(), 1)\n subdir(exec_env)\n \n", "prefixes": [] }{ "id": 105067, "url": "