Skip to content

Commit c326918

Browse files
authored
Merge pull request swiftlang#2657 from spevans/pr_sr_11411
SR-11411: Update GettingStarted.md
2 parents fc81252 + f8e46f0 commit c326918

File tree

2 files changed

+49
-44
lines changed

2 files changed

+49
-44
lines changed

Docs/GettingStarted.md

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ Although macOS is not a deployment platform for Swift Foundation, it is useful f
77
In order to build on macOS, you will need:
88

99
* The latest version of Xcode
10-
* The latest version of the macOS SDK (at this time: 10.14)
10+
* The latest version of the macOS SDK (at this time: 10.15)
1111
* The [current Swift toolchain](https://swift.org/download/#snapshots).
1212

13+
> Note: due to https://bugs.swift.org/browse/SR-12177 the default Xcode toolchain should be used for now.
14+
1315
Foundation is developed at the same time as the rest of Swift, so the most recent version of the compiler is required in order to build it.
1416

1517
The repository includes an Xcode project file as well as an Xcode workspace. The workspace includes both Foundation and XCTest, which makes it easy to build and run everything together. The workspace assumes that Foundation and XCTest are checked out from GitHub in sibling directories. For example:
@@ -30,71 +32,66 @@ Build and test steps:
3032

3133
> Note: If you see the name of the XCTest project file in red in the workspace, then Xcode cannot find the cloned XCTest repository. Make sure that it is located next to the `swift-corelibs-foundation` directory and has the name `swift-corelibs-xctest`.
3234
35+
### Darwin Compatibility Tests
36+
37+
In order to increase the compatibility between corelibs-foundation and the native Foundation shipped with macOS, there is another Xcode project in the `swift-corelibs-foundation` repository called `DarwinCompatibilityTests.xcodeproj`. This project just runs all of the `TestFoundation` tests using native Foundation. Ideally, any new test written for corelibs-foundation should be tested against
38+
native Foundation to validate that that test is correct. The tests can be run individually using the Test navigator in the left hand pane.
39+
40+
It should be noted that not all tests currently run correctly either due to differences between the two implentations, the test being used to validate some
41+
intenal functionality of corelibs-foundation or the test (and the implementation) actually being incorrect. Overtime these test differences should be reduced as compatibility is increased.
42+
43+
3344
## On Linux
3445

3546
You will need:
3647

37-
* A supported distribution of Linux. At this time, we support [Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 18.04](http://www.ubuntu.com).
48+
* A supported distribution of Linux. At this time, we support [Ubuntu 16.04 and Ubuntu 18.04](http://www.ubuntu.com).
3849

3950
To get started, follow the instructions on how to [build Swift](https://github.com/apple/swift#building-swift). Foundation is developed at the same time as the rest of Swift, so the most recent version of the `clang` and `swift` compilers are required in order to build it. The easiest way to make sure you have all of the correct dependencies is to build everything together.
4051

41-
The default build script does not include Foundation. To build Foundation and XCTest as well, pass `--xctest --foundation` to the build script.
42-
52+
The default build script does not include Foundation. To configure and build Foundation and TestFoundation including lldb for debugging and the correct ICU library, the following command can be used. All other tests are disabled to reduce build and test time. `--release` is used to avoid building LLVM and the compiler with debugging.
4353
```
44-
swift/utils/build-script --xctest --foundation -t
54+
% swift/utils/build-script --libicu --lldb --release --test --foundation --xctest \
55+
--foundation-build-type=debug --skip-test-swift --skip-build-benchmarks \
56+
--skip-test-lldb --skip-test-xctest --skip-test-libdispatch --skip-test-libicu --skip-test-cmark
4557
```
4658

47-
This will build and run the Foundation tests, in the Debug configuration.
59+
The build artifacts will be written to the subdirectory `build/Ninja-ReleaseAssert`. To use a different build directory set the `SWIFT_BUILD_ROOT` environment variable to point to a different directory to use instead of `build`.
4860

49-
After the complete Swift build has finished, you can iterate quickly on Foundation itself by simply invoking `ninja` in the Foundation directory.
61+
When developing on Foundation, it is simplest to write tests to check the functionality, even if the test is not something that can be used in the final PR, e.g. it runs continously to demostrate a memory leak. Tests are added
62+
to the appropiate file in the `TestFoundation` directory, and remember to add the test in to the `allTests` array in that file.
5063

51-
```
52-
cd swift-corelibs-foundation
53-
ninja
54-
```
64+
After the complete Swift build has finished you can iterate over changes you make to Foundation using `cmake` to build `TestFoundation` and run the tests.
65+
Note that `cmake` needs to be a relatively recent version, currently 3.15.1, and if this is not installed already
66+
then it is built as part of the `build-script` invocation. Therefore `cmake` may be installed in `build/cmake`.
5567

56-
This will build Foundation. To build and run the tests, use the `test` target:
5768

5869
```
59-
ninja test
70+
# Build TestFoundation
71+
% $SWIFT_BUILD_ROOT=build $BUILD_ROOT/cmake-linux-x86_64/bin/cmake --build $BUILD_ROOT/Ninja-ReleaseAssert/foundation-linux-x86_64/ -v -- -j4 TestFoundation
72+
# Run the tests
73+
% $SWIFT_BUILD_ROOT=build $BUILD_ROOT/cmake-linux-x86_64/bin/cmake --build $BUILD_ROOT/Ninja-ReleaseAssert/foundation-linux-x86_64/ -v -- -j4 test
6074
```
6175

62-
The ninja build script will print the correct command-line invocation for both running the tests and debugging the tests. The exact library path to use will depend on how Foundation itself was configured by the earlier `build-script`. For example:
76+
If `TestFoundation` needs to be run outside of `ctest`, perhaps to run under `lldb` or to run individual tests, then it can be run directly but an appropiate `LD_LIBRARY_PATH`
77+
needs to be set so that `libdispatch` and `libXCTest` can be found.
6378

6479
```
65-
% ninja test
66-
[5/5] Building Tests
67-
**** RUNNING TESTS ****
68-
execute:
69-
LD_LIBRARY_PATH=../build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation/:/home/user/Development/build/Ninja-ReleaseAssert/xctest-linux-x86_64 ../build/Ninja-ReleaseAssert/foundation-linux-x86_64/TestFoundation/TestFoundation
70-
**** DEBUGGING TESTS ****
71-
execute:
72-
LD_LIBRARY_PATH=../build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation/:/home/user/Development/build/Ninja-ReleaseAssert/xctest-linux-x86_64 lldb ../build/Ninja-ReleaseAssert/foundation-linux-x86_64/TestFoundation/TestFoundation
73-
%
80+
% export BUILD_DIR=build/Ninja-ReleaseAssert
81+
% export LD_LIBRARY_PATH=$BUILD_DIR/foundation-linux-x86_64/Foundation:$BUILD_DIR/xctest-linux-x86_64:$BUILD_DIR/libdispatch-linux-x86_64
82+
% $BUILD_DIR/foundation-linux-x86_64/TestFoundation.app/TestFoundation
7483
```
84+
To run only one test class or a single test, the tests to run can be specified as a command argument in the form of `TestFoundation.<TestClass>{/testName}` eg to run all of the tests in `TestDate` use
85+
`TestFoundation.TestDate`. To run just `test_BasicConstruction`, use `TestFoundation.TestDate/test_BasicConstruction`.
7586

76-
Just copy & paste the correct line.
77-
78-
When new source files or flags are added to the `build.py` script, the project will need to be reconfigured in order for the build system to pick them up. The top-level `swift/utils/build-script` can be used, but for quicker iteration you can use the following command to limit the reconfiguration to just the Foundation project:
87+
If the tests need to be run under `lldb`, use the following comand:
7988

8089
```
81-
% ninja reconfigure
82-
% ninja
90+
% export BUILD_DIR=build/Ninja-ReleaseAssert
91+
% export LD_LIBRARY_PATH=$BUILD_DIR/foundation-linux-x86_64/Foundation:$BUILD_DIR/xctest-linux-x86_64:$BUILD_DIR/libdispatch-linux-x86_64
92+
% $BUILD_DIR/lldb-linux-x86_64/bin/lldb $BUILD_DIR/foundation-linux-x86_64/TestFoundation.app/TestFoundation
8393
```
8494

85-
It is possible to build Foundation without the use of `build-script`. You can
86-
build with cmake. It currently requires clang, swift, and libdispatch (which
87-
are generally built as part of the swift build).
88-
89-
```
90-
cmake \
91-
-G Ninja \
92-
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
93-
-D CMAKE_C_COMPILER=build/Ninja-ReleaseAssert/llvm-linux-x86_64/bin/clang \
94-
-D CMAKE_Swift_COMPILER=build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc \
95-
-D dispatch_DIR=build/Ninja-ReleaseAssert/libdispatch-linux-x86_64/cmake/modules \
96-
-B build/Ninja-ReleaseAssert/foundation-linux-x86_64
97-
-S swift-corelibs-foundation
98-
ninja -C build/Ninja-ReleaseAssert/foundation-linux-x86_64
99-
```
95+
When new source files or flags are added to any of the `CMakeLists.txt` files, the project will need to be reconfigured in order for the build system to pick them up. Simply rerun the `cmake` command to build `TestFoundation` given above and it should be reconfigured and built correctly.
10096

97+
If `update-checkout` is used to update other repositories, rerun the `build-script` command above to reconfigure and rebuild the other libraries.

Foundation.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@
426426
B951B5EC1F4E2A2000D8B332 /* TestNSLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B951B5EB1F4E2A2000D8B332 /* TestNSLock.swift */; };
427427
B95FC97522AF051B005DEA0A /* xcode-build.sh in Resources */ = {isa = PBXBuildFile; fileRef = B95FC97422AF051B005DEA0A /* xcode-build.sh */; };
428428
B95FC97622B84B0A005DEA0A /* TestNSSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 152EF3932283457B001E1269 /* TestNSSortDescriptor.swift */; };
429+
B983E32C23F0C69600D9C402 /* Docs in Resources */ = {isa = PBXBuildFile; fileRef = B983E32B23F0C69600D9C402 /* Docs */; };
430+
B983E32E23F0C6E200D9C402 /* CONTRIBUTING.md in Resources */ = {isa = PBXBuildFile; fileRef = B983E32D23F0C6E200D9C402 /* CONTRIBUTING.md */; };
429431
B98E33DD2136AA740044EBE9 /* TestFileWithZeros.txt in Resources */ = {isa = PBXBuildFile; fileRef = B98E33DC2136AA740044EBE9 /* TestFileWithZeros.txt */; };
430432
B99EAE72236044C900C8FB46 /* SwiftXCTest.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = B95FC97222AF0050005DEA0A /* SwiftXCTest.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
431433
B9C0E89620C31AB60064C68C /* CFInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 5B5D888A1BBC963C00234F36 /* CFInternal.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1075,6 +1077,8 @@
10751077
B951B5EB1F4E2A2000D8B332 /* TestNSLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestNSLock.swift; sourceTree = "<group>"; };
10761078
B95FC97222AF0050005DEA0A /* SwiftXCTest.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftXCTest.framework; sourceTree = BUILT_PRODUCTS_DIR; };
10771079
B95FC97422AF051B005DEA0A /* xcode-build.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "xcode-build.sh"; sourceTree = "<group>"; };
1080+
B983E32B23F0C69600D9C402 /* Docs */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Docs; sourceTree = "<group>"; };
1081+
B983E32D23F0C6E200D9C402 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
10781082
B98E33DC2136AA740044EBE9 /* TestFileWithZeros.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = TestFileWithZeros.txt; sourceTree = "<group>"; };
10791083
B9974B8F1EDF4A22007F15B8 /* TransferState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransferState.swift; sourceTree = "<group>"; };
10801084
B9974B901EDF4A22007F15B8 /* MultiHandle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultiHandle.swift; sourceTree = "<group>"; };
@@ -1342,8 +1346,10 @@
13421346
5B5D88531BBC938800234F36 = {
13431347
isa = PBXGroup;
13441348
children = (
1345-
B95FC97422AF051B005DEA0A /* xcode-build.sh */,
13461349
B167A6641ED7303F0040B09A /* README.md */,
1350+
B983E32D23F0C6E200D9C402 /* CONTRIBUTING.md */,
1351+
B95FC97422AF051B005DEA0A /* xcode-build.sh */,
1352+
B983E32B23F0C69600D9C402 /* Docs */,
13471353
5BDC3F2C1BCC5DB500ED97BB /* Foundation */,
13481354
EAB57B681BD1A255004AC5C5 /* CoreFoundation */,
13491355
EA66F65B1BF2DF3200136161 /* Bootstrap */,
@@ -2658,6 +2664,8 @@
26582664
isa = PBXResourcesBuildPhase;
26592665
buildActionMask = 2147483647;
26602666
files = (
2667+
B983E32E23F0C6E200D9C402 /* CONTRIBUTING.md in Resources */,
2668+
B983E32C23F0C69600D9C402 /* Docs in Resources */,
26612669
);
26622670
runOnlyForDeploymentPostprocessing = 0;
26632671
};

0 commit comments

Comments
 (0)