Skip to content

Commit 3f0ddaa

Browse files
committed
ci: enable macos
fix cppalliance#558 fix cppalliance#694
1 parent da81e09 commit 3f0ddaa

File tree

6 files changed

+118
-23
lines changed

6 files changed

+118
-23
lines changed

.github/workflows/ci.yml

+28-18
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,26 @@ jobs:
3737
gcc 14
3838
clang 18
3939
msvc >=14.40
40+
apple-clang *
4041
standards: '20'
4142
latest-factors: ''
4243
factors: |
4344
msvc Optimized-Debug
45+
runs-on: |
46+
apple-clang: macos-15
4447
build-types: |
4548
gcc: Release
4649
clang: Release
50+
apple-clang: Release
4751
msvc: RelWithDebInfo
4852
msvc Optimized-Debug: Debug
4953
ccflags: |
5054
msvc Optimized-Debug: /Ob1 /O2 /Zi
5155
cxxflags: |
5256
msvc Optimized-Debug: /Ob1 /O2 /Zi
5357
install: |
54-
gcc: git build-essential pkg-config python3 curl openjdk-11-jdk ninja-build pkg-config libncurses-dev libxml2-utils libxml2-dev
55-
clang: git build-essential pkg-config python3 curl openjdk-11-jdk ninja-build pkg-config libncurses-dev libxml2-utils libxml2-dev
58+
gcc: git build-essential pkg-config python3 curl openjdk-11-jdk pkg-config libncurses-dev libxml2-utils libxml2-dev
59+
clang: git build-essential pkg-config python3 curl openjdk-11-jdk pkg-config libncurses-dev libxml2-utils libxml2-dev
5660
msvc: ''
5761
extra-values: |
5862
llvm-hash: e1065370aaacb1b1cb48e77d37d376bf024f4a39
@@ -68,6 +72,8 @@ jobs:
6872
llvm-archive-filename: {{ llvm-archive-basename }}.{{ llvm-archive-extension }}
6973
libcxx-runtimes: libcxx;libcxxabi{{#if (ine os 'windows') }};libunwind{{/if}}
7074
libcxx-targets: cxx {{#if (ine os 'windows') }}cxxabi unwind{{/if}} install-cxx {{#if (ine os 'windows') }}install-cxxabi install-unwind{{/if}}
75+
libcxx-cxxflags: {{#if (ieq os 'windows') }}-D__ORDER_LITTLE_ENDIAN__=1234 -D__ORDER_BIG_ENDIAN__=4321 -D__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__{{/if}}
76+
libcxx-cmake-args: -D LLVM_ENABLE_RUNTIMES="{{ libcxx-runtimes }}" {{#if (ieq os 'windows') }}-D LIBCXXABI_USE_LLVM_UNWINDER=OFF -D LIBCXXABI_ENABLE_SHARED=OFF -D LIBCXXABI_ENABLE_STATIC=ON -D LIBCXX_ENABLE_SHARED=OFF -D LIBCXX_NO_VCRUNTIME=ON{{/if}} {{#if (ieq os 'macos') }}-D CMAKE_OSX_ARCHITECTURES=""{{/if}}
7177
mrdocs-ccflags: {{ ccflags }} {{#if (eq compiler 'gcc') }}-static{{/if}} {{#if asan }}-static-libasan{{/if}} {{#if tsan }}-static-libtsan{{/if}}
7278
mrdocs-cxxflags: {{ cxxflags }} {{#if (eq compiler 'gcc') }}-static{{/if}} {{#if asan }}-static-libasan{{/if}} {{#if tsan }}-static-libtsan{{/if}}
7379
mrdocs-package-generators: {{#if (ieq os 'windows') }}7Z ZIP WIX{{else}}TGZ TXZ{{/if}}
@@ -131,8 +137,7 @@ jobs:
131137
trace-commands: 'true'
132138

133139
- name: Setup Ninja
134-
uses: seanmiddleditch/gha-setup-ninja@v4
135-
if: ${{ runner.os == 'Windows' }}
140+
uses: seanmiddleditch/gha-setup-ninja@v5
136141

137142
- name: Setup C++
138143
uses: alandefreitas/cpp-actions/[email protected]
@@ -141,6 +146,15 @@ jobs:
141146
compiler: ${{ matrix.compiler }}
142147
version: ${{ matrix.version }}
143148

149+
# If apple-clang on macos, we run `clang -print-targets` to
150+
# get the list of targets supported by the compiler.
151+
- name: Print Clang Targets
152+
if: matrix.compiler == 'apple-clang'
153+
run: |
154+
set -x
155+
${{ steps.setup-cpp.outputs.cxx }} --print-targets
156+
${{ steps.setup-cpp.outputs.cxx }} --print-target-triple
157+
144158
- name: Install System Packages
145159
uses: alandefreitas/cpp-actions/[email protected]
146160
if: matrix.compiler != 'msvc'
@@ -323,24 +337,19 @@ jobs:
323337
source-dir: ../third-party/llvm-project/runtimes
324338
build-dir: ${sourceDir}/build-libcxx
325339
build-target: ${{ matrix.libcxx-targets }}
326-
cc: ../third-party/llvm-project/install/bin/clang
327-
cxx: ../third-party/llvm-project/install/bin/clang++
328-
cxxflags: ${{ runner.os == 'Windows' && '-D__ORDER_LITTLE_ENDIAN__=1234 -D__ORDER_BIG_ENDIAN__=4321 -D__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__' || '' }}
340+
# MrDocs will only use the LibC++ headers: any compiler that works in this workflow will do
341+
cc: ${{ runner.os == 'macOS' && steps.setup-cpp.outputs.cc || '../third-party/llvm-project/install/bin/clang' }}
342+
cxx: ${{ runner.os == 'macOS' && steps.setup-cpp.outputs.cxx || '../third-party/llvm-project/install/bin/clang++' }}
343+
cxxflags: ${{ matrix.libcxx-cxxflags }}
329344
generator: Ninja
330-
extra-args: |
331-
-D LLVM_ENABLE_RUNTIMES="${{ matrix.libcxx-runtimes }}"
332-
${{ runner.os == 'Windows' && '-D LIBCXXABI_USE_LLVM_UNWINDER=OFF' || '' }}
333-
${{ runner.os == 'Windows' && '-D LIBCXXABI_ENABLE_SHARED=OFF' || '' }}
334-
${{ runner.os == 'Windows' && '-D LIBCXXABI_ENABLE_STATIC=ON' || '' }}
335-
${{ runner.os == 'Windows' && '-D LIBCXX_ENABLE_SHARED=OFF' || '' }}
336-
${{ runner.os == 'Windows' && '-D LIBCXX_NO_VCRUNTIME=ON' || '' }}
345+
extra-args: ${{ matrix.libcxx-cmake-args }}
337346
install: true
338347
install-prefix: ${sourceDir}/../install
339348
run-tests: false
340349
trace-commands: true
341350

342351
- name: Install Node.js
343-
uses: actions/setup-node@v3
352+
uses: actions/setup-node@v4
344353
with:
345354
node-version: '20'
346355

@@ -427,12 +436,12 @@ jobs:
427436
uses: actions/checkout@v4
428437

429438
- name: Install Node.js
430-
uses: actions/setup-node@v3
439+
uses: actions/setup-node@v4
431440
with:
432441
node-version: '18'
433442

434443
- name: Setup Ninja
435-
uses: seanmiddleditch/gha-setup-ninja@v4
444+
uses: seanmiddleditch/gha-setup-ninja@v5
436445
if: ${{ runner.os == 'Windows' }}
437446

438447
- name: Download MrDocs package
@@ -445,7 +454,8 @@ jobs:
445454
run: |
446455
set -x
447456
if [[ ${{ runner.os }} != 'Windows' ]]; then
448-
dest_dir="/usr/local"
457+
dest_dir="$HOME/local"
458+
mkdir -p "$dest_dir"
449459
find packages -maxdepth 1 -name 'MrDocs-*.tar.gz' -exec tar -vxzf {} -C $dest_dir --strip-components=1 \;
450460
else
451461
dest_dir="$GITHUB_WORKSPACE/usr/local"

docs/modules/ROOT/pages/install.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ export CXX="./install/bin/clang++"
407407
export CC="./install/bin/clang"
408408
----
409409

410+
These options set the C and pass:[C++] compilers to the ones previously installed by LLVM.
411+
MrDocs only depends on the pass:[LibC++] headers, so any compiler that works for this step should be fine.
412+
410413
Run a command such as the following to configure LLVM:
411414

412415
[tabs]

include/mrdocs/Platform.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ namespace mrdocs {
7272
# endif
7373
#endif
7474

75-
#if ! defined(__x86_64__) && ! defined(_WIN64)
76-
# error mrdox requires a 64-bit archtecture
75+
#if ! defined(__x86_64__) && ! defined(_WIN64) && ! defined(__aarch64__)
76+
# error mrdocs requires a 64-bit architecture
7777
#endif
7878

7979
} // mrdocs

src/lib/Lib/CMakeExecution.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ parseBashArgs(std::string_view str)
383383
return args;
384384
}
385385

386+
/* Pushes the CMake arguments to the `args` vector, replacing the
387+
* default generator with Ninja if Visual Studio is the default generator.
388+
*/
386389
Expected<void>
387390
pushCMakeArgs(
388391
std::string const& cmakePath,

src/lib/Lib/MrDocsCompilationDatabase.cpp

+81-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <llvm/Option/ArgList.h>
2222
#include <llvm/Option/OptTable.h>
2323
#include <llvm/Support/FileSystem.h>
24+
#include <llvm/Support/Program.h>
25+
#include <llvm/TargetParser/Host.h>
2426
#include <ranges>
2527

2628
namespace clang {
@@ -243,8 +245,8 @@ static
243245
std::vector<std::string>
244246
adjustCommandLine(
245247
llvm::StringRef workingDir,
246-
const std::vector<std::string>& cmdline,
247-
const std::vector<std::string>& additional_defines,
248+
std::vector<std::string> const& cmdline,
249+
std::vector<std::string> const& additional_defines,
248250
std::unordered_map<std::string, std::vector<std::string>> const& implicitIncludeDirectories,
249251
std::vector<std::string> const& stdlibIncludes,
250252
std::vector<std::string> const& systemIncludes,
@@ -292,6 +294,83 @@ adjustCommandLine(
292294
new_cmdline.emplace_back(is_clang_cl ? "/w" : "-w");
293295
new_cmdline.emplace_back("-fsyntax-only");
294296

297+
// ------------------------------------------------------
298+
// Target architecture
299+
// ------------------------------------------------------
300+
constexpr auto is_target_option = [](std::string_view opt) {
301+
return opt == "-target" || opt == "--target";
302+
};
303+
if (std::ranges::find_if(cmdline, is_target_option) == cmdline.end())
304+
{
305+
auto getCommandCompilerTarget = [&]() -> std::string {
306+
ScopedTempFile const outputPath("compiler-triple", "txt");
307+
if (!outputPath) {
308+
return {};
309+
}
310+
std::vector<llvm::StringRef> args = {
311+
progName, "--print-target-triple"
312+
};
313+
std::optional<llvm::StringRef> const redirects[] = {
314+
llvm::StringRef(),
315+
outputPath.path(),
316+
llvm::StringRef()
317+
};
318+
int const result = llvm::sys::ExecuteAndWait(
319+
progName, args, std::nullopt, redirects);
320+
if (result != 0)
321+
{
322+
return {};
323+
}
324+
325+
auto const bufferOrError = llvm::MemoryBuffer::getFile(
326+
outputPath.path());
327+
if (!bufferOrError) {
328+
return {};
329+
}
330+
return bufferOrError.get()->getBuffer().trim().str();
331+
};
332+
333+
[&]() {
334+
std::string target = llvm::sys::getDefaultTargetTriple();
335+
336+
if (target.empty())
337+
{
338+
target = llvm::sys::getProcessTriple();
339+
}
340+
341+
if (target.empty())
342+
{
343+
target = getCommandCompilerTarget();
344+
}
345+
346+
#if defined(__APPLE__)
347+
if (target.empty())
348+
{
349+
target = "arm64-apple-darwin24.0.0";
350+
}
351+
#else
352+
if (target.empty())
353+
{
354+
return;
355+
}
356+
#endif
357+
358+
new_cmdline.emplace_back("-target");
359+
new_cmdline.emplace_back(target);
360+
}();
361+
}
362+
363+
// ------------------------------------------------------
364+
// Language standard
365+
// ------------------------------------------------------
366+
constexpr auto is_std_option = [](std::string_view opt) {
367+
return opt.starts_with("-std=") || opt.starts_with("--std=") || opt.starts_with("/std:");
368+
};
369+
if (std::ranges::find_if(cmdline, is_std_option) == cmdline.end())
370+
{
371+
new_cmdline.emplace_back("-std=c++23");
372+
}
373+
295374
// ------------------------------------------------------
296375
// Add additional defines
297376
// ------------------------------------------------------

src/lib/Support/Error.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ call_impl(
258258
e->location().line());
259259
}
260260
os << fmt::format(
261-
" Reported From: `{}` at line {}",
261+
" Reported From: `{}` at line {}\n",
262262
::SourceFileNames::getFileName(loc->file_name()),
263263
loc->line());
264264
// VFALCO attach a stack trace for Level::fatal

0 commit comments

Comments
 (0)