Skip to content

Commit

Permalink
See issue #76: Pulling in slightly more advanced c code
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshjoshi committed Aug 1, 2022
1 parent feb7df2 commit 5624f70
Show file tree
Hide file tree
Showing 18 changed files with 97 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"python.formatting.provider": "black"
"python.formatting.provider": "black",
"files.associations": {
"iostream": "cpp"
}
}
12 changes: 6 additions & 6 deletions build-support/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ function die() {

MERGE_BASE="$(git_merge_base)"

echo "* Build file checking"
./pants --changed-since="${MERGE_BASE}" update-build-files --check ||
die "If there were errors, run \`./pants --changed-since=$(git rev-parse --symbolic "${MERGE_BASE}") update-build-files\`"
# echo "* Build file checking"
# ./pants --changed-since="${MERGE_BASE}" update-build-files --check ||
# die "If there were errors, run \`./pants --changed-since=$(git rev-parse --symbolic "${MERGE_BASE}") update-build-files\`"

echo "* Lint checking"
./pants --changed-since="${MERGE_BASE}" lint ||
die "If there were formatting errors, run \`./pants --changed-since=$(git rev-parse --symbolic "${MERGE_BASE}") fmt\`"
# echo "* Lint checking"
# ./pants --changed-since="${MERGE_BASE}" lint ||
# die "If there were formatting errors, run \`./pants --changed-since=$(git rev-parse --symbolic "${MERGE_BASE}") fmt\`"

# echo "* Typechecking"
# ./pants --changed-since="${MERGE_BASE}" --changed-dependees=transitive check
8 changes: 8 additions & 0 deletions hellocpp/app/src/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cc_sources(
name="lib"
)

cc_binary(
name="out",
dependencies=["lib"]
)
6 changes: 6 additions & 0 deletions hellocpp/app/src/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "foo.h"

int add(int a, int b)
{
return a + b;
}
5 changes: 5 additions & 0 deletions hellocpp/app/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef FOO_H

int add(int a, int b);

#endif
11 changes: 11 additions & 0 deletions hellocpp/app/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

#include "core/greeter.h"
#include "foo.h"

int main()
{
auto result = add(1, 2);
const auto greet();
std::cout << "Hello, world! " << result << std::endl;
}
File renamed without changes.
1 change: 1 addition & 0 deletions hellocpp/core/include/core/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc_sources()
13 changes: 13 additions & 0 deletions hellocpp/core/include/core/greeter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef CORE_GREETER_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void greet(void);

#ifdef __cplusplus
}
#endif //__cplusplus

#endif // CORE_GREETER_H
1 change: 1 addition & 0 deletions hellocpp/core/src/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc_sources()
6 changes: 6 additions & 0 deletions hellocpp/core/src/greeter-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef CORE_GREETER_PRIVATE_H

// This file only exists to ensure that private and exported headers can work together
char greetingSymbol(void);

#endif // CORE_GREETER_PRIVATE_H
17 changes: 17 additions & 0 deletions hellocpp/core/src/greeter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "core/greeter.h"

#include "greeter-private.h"
#include <stdio.h>

// Declared in core/greeter.h
void greet(void)
{
char symbol = greetingSymbol();
printf("Greetings, world%c", symbol);
}

// Declared in greeter-private.h
char greetingSymbol(void)
{
return '!';
}
24 changes: 12 additions & 12 deletions helloswift/BUILD.pants
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
swift_sources(
name="libcore",
sources=["Core/*.swift"],
)
#swift_sources(
# name="libcore",
# sources=["Core/*.swift"]
#)

swift_sources(
name="libhelloworld",
sources=["Sources/*.swift"],
)
#swift_sources(
# name="libhelloworld",
# sources=["Sources/*.swift"]
#)

swift_binary(
name="bin",
dependencies=[":lib"],
)
#swift_binary(
# name="bin",
# dependencies=[":lib"]
#)
3 changes: 2 additions & 1 deletion pants-plugins/experimental/cc/goals/check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from typing import Iterable
from pants.engine.rules import collect_rules, Rule, UnionRule

from pants.engine.rules import Rule, UnionRule, collect_rules


def rules() -> Iterable[Rule | UnionRule]:
Expand Down
1 change: 0 additions & 1 deletion pants-plugins/experimental/cc/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ def rules() -> Iterable[Rule | UnionRule]:
*compile.rules(),
*toolchain.rules(),
)

3 changes: 2 additions & 1 deletion pants-plugins/experimental/cc/subsystems/toolchain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from typing import Iterable
from pants.engine.rules import collect_rules, Rule, UnionRule

from pants.engine.rules import Rule, UnionRule, collect_rules


def rules() -> Iterable[Rule | UnionRule]:
Expand Down
3 changes: 2 additions & 1 deletion pants-plugins/experimental/cc/util_rules/compile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from typing import Iterable
from pants.engine.rules import collect_rules, Rule, UnionRule

from pants.engine.rules import Rule, UnionRule, collect_rules


def rules() -> Iterable[Rule | UnionRule]:
Expand Down
2 changes: 1 addition & 1 deletion pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ backend_packages = [
#"experimental.mypyc",
#"experimental.ansible",
#"experimental.ansible.lint.ansible_lint",
"experimental.swift",
#"experimental.swift",
]

[source]
Expand Down

0 comments on commit 5624f70

Please sign in to comment.