Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MinGW specialized toolchain and target#179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
coder137 merged 20 commits intomainfrommingw_specialized
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
20 commits
Select commitHold shift + click to select a range
e0786e9
Update style_guide.rst
coder137Jan 4, 2022
246136b
Create toolchain_mingw.h
coder137Jan 4, 2022
697e992
Create target_mingw.h
coder137Jan 4, 2022
92186f2
Added mingw executable example
coder137Jan 4, 2022
7201419
Update buildcc.h
coder137Jan 4, 2022
784fc18
Update CMakeLists.txt
coder137Jan 4, 2022
df3519d
Update CMakeLists.txt
coder137Jan 4, 2022
1dcd1a5
Added Mingw StaticLib example
coder137Jan 4, 2022
e05deee
Update target_mingw.h
coder137Jan 4, 2022
46698bc
Added mingw DynamicLib examples
coder137Jan 4, 2022
941c40d
Update target_mingw.h
coder137Jan 4, 2022
6af2e6a
Update build.cpp
coder137Jan 4, 2022
657487c
Added Mingw pch example
coder137Jan 4, 2022
7457bf3
Update target_mingw.h
coder137Jan 4, 2022
41a01ad
Update build.cpp
coder137Jan 4, 2022
b01ec5d
Update target_mingw.h
coder137Jan 4, 2022
b6c4080
Update mingw.rst
coder137Jan 4, 2022
7356e2a
Update build.cpp
coder137Jan 4, 2022
34c2c0b
Update mingw.rst
coder137Jan 4, 2022
4c49f75
Update README.md
coder137Jan 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletionbuildcc/buildcc.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Niket Naidu. All rights reserved.
* Copyright 2021-2022 Niket Naidu. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand DownExpand Up@@ -37,12 +37,14 @@
// Specialized Toolchain
#include "toolchains/toolchain_gcc.h"
#include "toolchains/toolchain_msvc.h"
#include "toolchains/toolchain_mingw.h"

// TODO, Add more specialized toolchains here

// Specialized Targets
#include "targets/target_gcc.h"
#include "targets/target_msvc.h"
#include "targets/target_mingw.h"
#include "targets/target_generic.h"
#include "targets/target_custom.h"

Expand Down
1 change: 1 addition & 0 deletionsbuildcc/targets/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ set(TARGET_SPECIALIZED_SRCS
# Specialized targets
include/targets/target_gcc.h
include/targets/target_msvc.h
include/targets/target_mingw.h

# User targets
include/targets/target_generic.h
Expand Down
87 changes: 87 additions & 0 deletionsbuildcc/targets/include/targets/target_mingw.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2021-2022 Niket Naidu. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TARGETS_TARGET_MINGW_H_
#define TARGETS_TARGET_MINGW_H_

#include "target/target.h"

#include "target_config_interface.h"
#include "target_gcc.h"

// MinGW
// ".exe", ".a", ".so" -> (x86_64-w64-mingw32)
namespace buildcc {

// Extensions
constexpr const char *const kMingwExecutableExt = ".exe";
constexpr const char *const kMingwDynamicLibExt = ".dll";

constexpr const char *const kMingwDynamicLibLinkCommand =
"{cpp_compiler} -shared {link_flags} {compiled_sources} -o {output} "
"-Wl,--out-implib,{output}.a";

class MingwConfig : ConfigInterface<MingwConfig> {
public:
static TargetConfig Executable() {
return DefaultMingwConfig(kMingwExecutableExt, kGccGenericCompileCommand,
kGccExecutableLinkCommand);
}

static TargetConfig DynamicLib() {
return DefaultMingwConfig(kMingwDynamicLibExt, kGccGenericCompileCommand,
kMingwDynamicLibLinkCommand);
}

private:
static TargetConfig DefaultMingwConfig(const std::string &target_ext,
const std::string &compile_command,
const std::string &link_command) {
TargetConfig config;
config.target_ext = target_ext;
config.obj_ext = kGccObjExt;
config.pch_header_ext = kGccPchHeaderExt;
config.pch_compile_ext = kGccPchCompileExt;
std::string prefix_include_dir = kGccPrefixIncludeDir;
std::string prefix_lib_dir = kGccPrefixLibDir;
config.pch_command = kGccGenericPchCompileCommand;
config.compile_command = compile_command;
config.link_command = link_command;
return config;
}
};

class ExecutableTarget_mingw : public ExecutableTarget_gcc {
public:
ExecutableTarget_mingw(const std::string &name,
const BaseToolchain &toolchain, const TargetEnv &env,
const TargetConfig &config = MingwConfig::Executable())
: ExecutableTarget_gcc(name, toolchain, env, config) {}
};

typedef StaticTarget_gcc StaticTarget_mingw;

class DynamicTarget_mingw : public DynamicTarget_gcc {
public:
DynamicTarget_mingw(const std::string &name, const BaseToolchain &toolchain,
const TargetEnv &env,
const TargetConfig &config = MingwConfig::DynamicLib())
: DynamicTarget_gcc(name, toolchain, env, config) {}
};

} // namespace buildcc

#endif
1 change: 1 addition & 0 deletionsbuildcc/toolchains/CMakeLists.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
set(TOOLCHAIN_SPECIALIZED_SRCS
include/toolchains/toolchain_gcc.h
include/toolchains/toolchain_msvc.h
include/toolchains/toolchain_mingw.h
)

if(${BUILDCC_BUILD_AS_SINGLE_LIB})
Expand Down
33 changes: 33 additions & 0 deletionsbuildcc/toolchains/include/toolchains/toolchain_mingw.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2021-2022 Niket Naidu. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TOOLCHAINS_TOOLCHAIN_MINGW_H_
#define TOOLCHAINS_TOOLCHAIN_MINGW_H_

#include "toolchain/toolchain.h"

namespace buildcc {

class Toolchain_mingw : public BaseToolchain {
public:
Toolchain_mingw()
: Toolchain(ToolchainId::MinGW, "gcc", "as", "gcc", "g++", "ar", "ld") {}
Toolchain_mingw(const Toolchain_mingw &) = delete;
};

} // namespace buildcc

#endif
4 changes: 3 additions & 1 deletiondocs/source/arch/style_guide.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,6 +15,8 @@ Google Style

``[snake_case_variable_name]_`` for private member variables

``k[PascalCaseVariableName]`` constexpr variables and enum / enum classes names
``k[PascalCaseVariableName]`` constexpr variables and enum / enum classes names ONLY when used internally

``[PascakCaseVariableName]`` constexpr variables and enum / enum classes names when exposed to users

.. attention:: If you see any wrong usage in the project please raise an issue
169 changes: 169 additions & 0 deletionsdocs/source/examples/mingw.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,3 +2,172 @@ MinGW
=======

Lowlevel MinGW Tests


Executable
-----------

.. code-block:: cpp
:linenos:
:emphasize-lines: 2,6

// MINGW specialized Toolchain
Toolchain_mingw mingw;

// MINGW specialized targets
// Creates `Simple.exe`
ExecutableTarget_mingw exetarget("Simple", mingw, "");
exetarget.GlobSources("src");
exetarget.AddIncludeDir("include", true);
exetarget.Build();

// Build
tf::Executor executor;
executor.run(exetarget.GetTaskflow());
executor.wait_for_all();

StaticLib
----------

.. code-block:: cpp
:linenos:
:emphasize-lines: 2,6,13

// MINGW specialized Toolchain
Toolchain_mingw mingw;

// MINGW specialized targets
// Creates `librandom.lib`
StaticTarget_mingw statictarget("librandom", mingw, "");
statictarget.AddSource("src/random.cpp");
statictarget.AddIncludeDir("include", true);
statictarget.Build();

// MINGW specialized targets
// Creates `Simple.exe`
ExecutableTarget_mingw exetarget("Simple", mingw, "");
exetarget.AddSource("src/main.cpp");
exetarget.AddIncludeDir("include", true);
exetarget.AddLibDep(statictarget);
exetarget.Build();

// Build
tf::Executor executor;
tf::Taskflow taskflow;

// Setup your dependencies explicitly
// Here statictarget needs to be built before exetarget
auto statictargetTask = taskflow.composed_of(statictarget.GetTaskflow());
auto exetargetTask = taskflow.composed_of(exetarget.GetTaskflow());
exetargetTask.succeed(statictargetTask);

executor.run(taskflow);
executor.wait_for_all();

DynamicLib
-----------

.. code-block:: cpp
:linenos:
:emphasize-lines: 2,6,13

// MINGW specialized Toolchain
Toolchain_mingw mingw;

// MINGW specialized targets
// Creates `librandom.lib` and `librandom.lib.dll`
DynamicTarget_mingw dynamictarget("librandom", mingw, "");
dynamictarget.AddSource("src/random.cpp");
dynamictarget.AddIncludeDir("include", true);
dynamictarget.Build();

// MINGW specialized target
// Creates `Simple.exe` which uses the above dynamic library
ExecutableTarget_mingw exetarget("Simple", mingw, "");
exetarget.AddSource("src/main.cpp");
exetarget.AddIncludeDir("include", true);
exetarget.AddLibDep(dynamictarget);
exetarget.Build();

// Build
tf::Executor executor;
tf::Taskflow taskflow;

// Setup your dependencies explicitly
// Here dynamictarget needs to be built before exetarget
auto dynamictargetTask = taskflow.composed_of(dynamictarget.GetTaskflow());
auto exetargetTask = taskflow.composed_of(exetarget.GetTaskflow());
exetargetTask.succeed(dynamictargetTask);

executor.run(taskflow);
executor.wait_for_all();

// Now that both your targets are built, copy the dynamictarget DLL to the exetarget location
// This is required for your exetarget to run properly
if (exetarget.IsBuilt()) {
fs::path copy_to_path =
exetarget.GetTargetBuildDir() / dynamictarget.GetTargetPath().filename();
fs::remove_all(copy_to_path);
fs::copy(dynamictarget.GetTargetPath(), copy_to_path);
}


.. note:: Our ``ExecutableTarget_mingw`` depends on ``DynamicTarget_mingw`` and requires the ``librandom.dll`` file to be present in the same folder location as the executable when running.

PrecompileHeader
-------------------

.. code-block:: cpp
:linenos:
:emphasize-lines: 2,4,7,24,25,26,39,40,41

int main() {
Toolchain_mingw mingw;

ExecutableTarget_mingw g_cppflags("cppflags", mingw, "files");
cppflags_build_cb(g_cppflags);

ExecutableTarget_mingw g_cflags("cflags", mingw, "files");
cflags_build_cb(g_cflags);

tf::Executor executor;
tf::Taskflow taskflow;

taskflow.composed_of(g_cppflags.GetTaskflow());
taskflow.composed_of(g_cflags.GetTaskflow());
executor.run(taskflow);
executor.wait_for_all();
}

static void cppflags_build_cb(BaseTarget &cppflags) {
cppflags.AddSource("main.cpp", "src");
cppflags.AddSource("random.cpp", "src");
cppflags.AddIncludeDir("include", true);

cppflags.AddPch("pch/pch_cpp.h");
cppflags.AddPch("pch/pch_c.h");
cppflags.AddIncludeDir("pch", true);

cppflags.AddPreprocessorFlag("-DRANDOM=1");
cppflags.AddCppCompileFlag("-Wall");
cppflags.AddCppCompileFlag("-Werror");
cppflags.AddLinkFlag("-lm");

cppflags.Build();
}

static void cflags_build_cb(BaseTarget &cflags) {
cflags.AddSource("main.c", "src");

cflags.AddPch("pch/pch_c.h");
cflags.AddIncludeDir("pch", false);
cflags.AddHeader("pch/pch_c.h");

cflags.AddPreprocessorFlag("-DRANDOM=1");
cflags.AddCCompileFlag("-Wall");
cflags.AddCCompileFlag("-Werror");
cflags.AddLinkFlag("-lm");

cflags.Build();
}

12 changes: 8 additions & 4 deletionsexample/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,9 +62,7 @@ Multi hosts but only one target compiler used

> NOTE, See the distinction between **HOST** and **TARGET**

## [host] MinGW GCC/GNU -> [target] gcc
## [host] MSVC -> [target] gcc
## [host] Linux GCC/GNU -> [target] gcc
## [target] Gcc

- [x] Simple
- Only 1 source file
Expand All@@ -84,7 +82,7 @@ Multi hosts but only one target compiler used
- [ ] ClangFormat
- [ ] Taskflow graph visualizer

## [host] MSVC -> [target] MSVC
## [target] MSVC

> TODO, Understand how MSVC compilation using `cl.exe` occurs

Expand All@@ -95,6 +93,12 @@ Multi hosts but only one target compiler used
- [x] DynamicLib
- MSVC DynamicLib + Executable

## [target] MinGW

- [x] Executable
- [x] StaticLib
- [x] DynamicLib

# Real world Tests (Hybrid)

Multi hosts and multi targets
Expand Down
8 changes: 8 additions & 0 deletionsexample/mingw/DynamicLib/.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
# Folder
generated
buildcc

# Files
*.exe
*.o
*.bin
Loading

[8]ページ先頭

©2009-2025 Movatter.jp