rnburn / rules_cc_module

Rules for using C++20 modules with bazel
Apache License 2.0
41 stars 4 forks source link

Add support for clang #11

Closed rnburn closed 2 years ago

rnburn commented 3 years ago

For clang (reference), to compile a module

// math-m.cc

export module math;

export int add(int a, int b) {
    return a + b;
} 

run

clang++ -std=c++20 - -fmodules-ts -stdlib=libc++ -c math-m.cc -Xclang -emit-module-interface -o math.pcm

when compiling sources that depend on modules (for example, modules A and B) use the -fmodule-file option.

// main.cc
import A;
import B;

...

clang++ -fmodules-ts -std=c++20 -fmodule-file=A=/path/to/a.pcm -fmodule-file=B=/path/to/b.pcm-c main.cc -o main.o

rnburn commented 3 years ago

See also this blog post and this blog post

rnburn commented 3 years ago

Examples of usage commands: https://github.com/llvm-mirror/clang/commit/cab7f1f7bc141ac88d15030088b311bd450b2c94

rnburn commented 2 years ago

done