Commit Graph

371 Commits

Author SHA1 Message Date
JP Simard 1f5cc7ac33
Remove Foundation dependency 2022-12-10 14:39:52 -05:00
JP Simard 740d49c99b
Basic CLI 2022-12-09 10:45:15 -05:00
Yuta Saito cd43968868
Build CYaml as PIC explicitly to link it agaist libYams.so (#353)
CYaml has been a private dependency of libYams.so and linked statically
against it since 2a93d740ef.
Therefore, CYaml should be built as PIC, but it wasn't.

Since gas 2.31 (Ubuntu 20.04), which includes implicit promotion of
non-PIC reloc (R_X86_64_PC32) to PIC reloc (R_X86_64_PLT32)[^1], this
issue is not revealed. However gas older than 2.31 (Ubuntu 18.04), this
PIC-ness mismatch causes linking failure with the following output:

```
/usr/bin/ld.gold: error: lib/libCYaml.a(api.c.o): requires dynamic R_X86_64_PC32 reloc against 'yaml_realloc' which may overflow at runtime; recompile with -fPIC
/usr/bin/ld.gold: error: lib/libCYaml.a(scanner.c.o): requires dynamic R_X86_64_PC32 reloc against 'yaml_parser_fetch_more_tokens' which may overflow at runtime; recompile with -fPIC
```

This patch fixes the PIC-ness mismatch by enabling
`POSITION_INDEPENDENT_CODE` explicitly, and adds CI job to check cmake
build system works on Ubuntu 18.04.

[^1]: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bd7ab16b4537788ad53521c45469a1bdae84ad4a
2022-04-28 13:38:03 -04:00
Saleem Abdulrasool 2a93d740ef
Yams: make `CYaml` private to Yams (#343)
This changes how `CYaml` is built and used within Yams.  As there are no
interfaces from `CYaml` being directly exposed, we can statically link
the library.  However, this still would cause a problem as the `CYaml`
import would be serialized into the module requiring that the module is
available when building anything which consumes `Yams`.  To avoid that,
change the `import CYaml` instances to `@_implementationOnly`.  This
allows for `CYaml` to not be required at the consumer site.

While in the area of the CMake build system, clean up some of the build
system to use language specific options.  This is required to avoid the
de-duplication of the options across languages and enables linking
`CYaml` statically into the library.  Note that on Windows static
linking of *Swift* libraries is not yet properly supported and this does
not enable that nor use that - it is statically linking *C* content.

This now allows building Yams dynamically as a single library target.
On Windows, this is a negligible space savings of ~16KiB.
2022-02-15 17:10:37 -08:00
Terence J. Grant e01df7ded9
Add `sequenceStyle` and `mappingStyle` to `Emitter.Options` (#340)
## Summary:

This adds `sequenceStyle` and `mappingStyle` options to `Emitter.Options`, which allows those using `YAMLEncoder` to specify whether "sequences" and "mappings" use `block` style (the default style) or `flow` style.

Also, CHANGELOG.md was updated and Podspec version was bumped to 4.0.7.

No unit test coverage was added, as there isn't direct unit test coverage for `Emitter.Options`, however there are already tests around mapping and sequence styles in the `EmitterTests` class, so this should be sufficient.

_**Note:** "sequences" are arrays / lists, "mappings" are dictionaries_

## Strategy:

`sequenceStyle` and `mappingStyle` were added to `Emitter.Options`, and changes were cascaded down into `Emitter`, `Encoder`, and `Node` where necessary. The existing field `sortKeys` in `Emitter.Options` was used as a guide to see where both `sequenceStyle` and `mappingStyle` should be added in other places in the code. Otherwise, minimal code changes were made to gain the desired feature.

## Examples:

Given an example YAML file here:

```
structure:
  edges:
    e1:
    - n1
    - n2
    e2:
    - n1
    - n3
    e3:
    - n2
    - n3
  nodes:
  - n1
  - n2
  - n3
```

### `sequenceStyle`

Setting `sequenceStyle` to `.flow` now generates:

```
structure:
  edges:
    e1: [n1, n2]
    e2: [n1, n3]
    e3: [n2, n3]
  nodes: [n1, n2, n3]
```

Which can be more visually pleasing, readable, and compact in certain scenarios such as this one.

### `mappingStyle`

Setting `mappingStyle` to `.flow` now generates:

```
{structure: {edges: {e1: [n1, n2], e2: [n1, n3], e3: [n2, n3]}, nodes: [n1, n2, n3]}}
```

Which may not be as visually pleasing with larger YAML files, but still could be useful in certain scenarios, and having the option to configure `mappingStyle` does "match parity" with being able to configure `sequenceStyle`.

Also you might notice, setting `mappingStyle` to `.flow` also forces `sequenceStyle` to be `.flow`, but this is not an error as for "flow" style to be used correctly with mappings at the top level, it must be enforced recursively through each child. (Implying, child mappings and child sequences must also be "flow" style.)
2022-01-07 14:59:12 -05:00
Mattt 64f37c1adc
Fix typos in documentation comments (#326)
* Fix typo: intendation -> indentation

* Fix typo: emmitter -> emitter
2021-06-22 09:00:39 -04:00
JP Simard 22740fe250
Fix CocoaPods (#314) 2021-04-07 09:01:05 -07:00
Maxwell Elliott 3ed41e1acf
Move Yams Bazel targets to the top level (#310)
Currently developers cannot access these nested targets, moving to the
top level will allow them to consume them in their bazel projects
2021-03-23 14:58:54 -07:00
JP Simard 409e565756
Update libyaml (#307)
Changes: 53f5b86...acd6f6f
2021-03-22 11:59:22 -07:00
Maxwell Elliott 6780f317eb
Add bazel support to Yams (#302)
Also add a GitHub action to ensure builds are working.

Validated on all Apple platforms and Linux.
2021-03-22 10:27:51 -07:00
Saleem Abdulrasool 3a1b1f8c23
CYaml: correct platform check (#303)
The target macro for Windows `_WIN32`.  We would fail to build with CMake on Windows when building with shared libraries.
2021-03-15 07:55:21 -07:00
JP Simard bf7793c6f5
Simplification 2021-01-19 15:25:05 -05:00
Brentley Jones 8695c0bd11
Expose the underlying Node's Mark on Decoder (#296)
This allows accessing source location during decoding.
2021-01-11 13:58:33 -06:00
Brentley Jones 11ab354492
Fix mark for sequences and mappings (#297)
Instead of the start mark for the sequence or map we were capturing the start mark of the _next_ element.
2021-01-11 12:33:06 -06:00
JP Simard 3824257669
Fix SwiftLint violations (#290) 2020-11-11 08:27:27 -08:00
JP Simard 27bbb8ddd0
Simplify imports in Representer.swift (#288)
* Simplify imports in Representer.swift

* Update Xcode versions available on CI

From https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md#xcode
2020-11-11 07:42:14 -08:00
Saleem Abdulrasool 682d4985e3
Yams: add an alias to explicitly dispatch `pow` (#281)
We must disambiguate `Double.pow(_: Double, _: Double) -> Double` and
`__C.pow(_: Double, _: Double) -> Double` as the Swift for TensorFlow
branch adds the former into the standard library.  The explicit module
dispatch ensures that we make the overload resolution unambiguous
allowing building Yams.
2020-10-26 09:01:08 -07:00
Saleem Abdulrasool ae37c14e9a
Yams: replace use of `MSVCRT` (#280)
Replace `MSVCRT` with `ucrt`.  There is nothing being used from the
`MSVCRT` module, prefer using `ucrt`.
2020-10-14 21:20:32 -04:00
JP Simard b9eba20519
Remove migration helpers (#278)
These were deprecated 3 years ago
2020-09-25 08:25:37 -07:00
Mathew Polzin 5cf653d248
Fix and test string -> integer misstep upon decoding. (#264)
Fixes https://github.com/jpsim/Yams/issues/263 by only constructing integer and floating point values from scalars if those scalars are in the `plain` "flow" style. It additionally allows through scalars with no styling information (`any`).
2020-09-10 10:15:03 -07:00
Gary Miguel 870b9696a2 Fix build with tensorflow toolchain
Due to https://bugs.swift.org/browse/TF-1203, there's a build failure
without this patch:

```
error: static member 'pow' cannot be used on instance of type 'Double'
```
2020-08-31 16:51:56 +00:00
Saleem Abdulrasool 70140a180a Yams: repair the build with the autodifferentiation toolchain
```
error: static member 'pow' cannot be used on instance of type 'Double'
```

When building Yams with the TensorFlow toolchain, this crops us.  Simply
add the explicit type annotation.
2020-08-21 11:05:23 -07:00
Saleem Abdulrasool cdafa7712f build: improve installation
We would previously fail to install Yams from CMake due to searching for
the swiftmodule in the wrong location.  This uses the new improved
generic installation rules that I've been using in a number of other
projects to install the swift content across all the platforms.
2020-08-17 10:45:17 -07:00
JP Simard 6e6483a6dd
Make YAMLDecoder conform to TopLevelDecoder (#262)
* Add TopLevelDecoder conformance

* fixup! Add TopLevelDecoder conformance

* Support decoding `Data`

- Set `TopLevelDecoder.Input` to `Data`
- Provide `YAMLDecoder.deecode(...)` function taking `Data` as input
- Add tests for `TopLevelDecoder` and `Data` decoding
- Add `Parser.Encoding.swiftStringEncoding` member to convert between the Swift String encoding and the Yams encoding
- Fix warnings with Swift 5.3

* Add TopLevelDecoderTests to CMakeLists.txt

* Only add TopLevelDecoderTests.swift to LinuxMain.swift if Combine is available

* Completely remove TopLevelDecoderTests from LinuxMain

* Use @available attribute

* Store cancellable

* 5.3

* Force unwrap

* merge compiler conditionals

* Fixes

* Try to run TopLevelDecoderTests with Swift 5.2+

* Only report code coverage for latest Xcode version

* Update README

* Remove stored cancellable

* Add changelog entries

* Install latest SwiftLint available to Homebrew
2020-07-06 20:54:51 -04:00
Saleem Abdulrasool 11bbadede6
Yams: remove conditional cases for Windows (#259)
Unify the non-Windows and Windows paths.  The full codebase now builds
without any special case for Windows.
2020-05-18 07:14:43 -07:00
Saleem Abdulrasool 84621a6025
build: add the ability to run the test suite from CMake (#256)
Expand the CMake based build to support running the test suite.  This
allows testing on Windows as well.  Although the test suite does not
fully pass on Windows yet, this brings us closer.

With this on Windows, the following is the result:

```
  Test Suite 'All tests' failed at 2020-05-14 12:11:08.871
           Executed 120 tests, with 9 failures (0 unexpected) in 0.505 (0.505) seconds
```

The failures in the test suite correspond to the conversion of floating
point values in the infinity and NaN cases (either converting to
`-infe+0`, `infe+0`, or `nane+0` instead of `-inf`, `inf`, `nan`, or
converting to `NaN` instead of `nan`).
2020-05-15 16:39:33 -07:00
Saleem Abdulrasool 170ac41044 build: simplify Foundation handling
Enable building against an uninstalled copy of Foundation but do not
require it.  This allows for a simpler build system.  If the user wishes
to build against an out-of-tree Foundation, they can simply specify
`Foundation_DIR` and `dispatch_DIR` when configuring and CMake will
handle the rest.
2020-05-14 20:06:53 -07:00
Saleem Abdulrasool 7fa1c3c7e4 build: use a single top-level Swift module directory
Rather than have a swift module directory that you need to find for each
library, use a single global swift module directory similar to the
runtime output directory.  This will be useful for a follow up change to
enable tests.
2020-05-14 14:50:15 -07:00
JP Simard b2537bc463
Fix CMake (#251)
The CMake instructions in the readme didn't quite work when I tried them on macOS today.

This patch includes a few changes to `CMakeLists.txt` and the `README.md` instructions to reflect the latest steps to build.

Also add a CI job to validate that this keeps working moving forward.
2020-05-08 13:50:29 -07:00
JP Simard 775dec7923
Require Swift 5.1 to build (#249) 2020-04-17 22:00:58 -07:00
JP Simard 937f397527
Fix `Yams.dump` when object contains a keyed null value (#248) 2020-04-17 14:47:21 -07:00
JP Simard 9e1f96b6f9
Reduce accessibility of members that should be private (#247) 2020-04-16 16:56:22 -07:00
JP Simard d53badf0fb
Run CI jobs with Swift 5.2 (#246)
* Run CI jobs with Swift 5.2

* Fix dangling pointer warning with Swift 5.2

* Only check code coverage in Sources/Yams

* Add changelog entry
2020-04-16 15:45:23 -07:00
Brentley Jones 5fa313eae1 Fix `YAMLDecoder` to support merging anchors (#238)
Currently `YAMLDecoder` uses `Resolver.basic` instead of `Resolver.default`, since it doesn't need to resolve types. This has the side effect of not including `.merge` as an option, making `decode` fail to see anchored properties.
2020-01-09 10:48:54 -08:00
Saleem Abdulrasool edb73d167c build: add CMake based build
This adds a CMake (3.15.1) based build to enable building Yams on
platforms where s-p-m does not yet function.  It also enables
cross-compilation of Yams.  This is sufficient to be able to build for
Windows with the following command line:

```
cmake -H build\debug -G Ninja -DFoundation_DIR=... -DCMAKE_Swift_COMPILER=...
cmake --build build\debug
```
2019-11-13 11:28:28 -08:00
JP Simard acd65f2035
Remove unused declaration (#214) 2019-10-20 10:42:03 -07:00
JP Simard 4a37b2b129
Fix SwiftLint violations (#212)
* colon placement
* line length
* mark format
* trailing collection literal comma
2019-10-20 10:32:41 -07:00
Ondrej Rafaj 725819d914 Add UUID support (#205)
* Adding UUID

* Fix docstring

* Fix lint issues & run testUUID on Linux

* Add changelog entry
2019-10-19 22:53:59 -07:00
Saleem Abdulrasool 5e5bdd040a Yams: explicitly cast value for enums (#208)
Enums on Windows are different from Linux and macOS.  Add explicit casts
for the values to be constructed.  This is needed for building YAMS on
Windows.
2019-10-19 14:57:07 -07:00
Saleem Abdulrasool d40456077a CYaml: add explicit modulemap
Yams uses CYaml which requires a module.  s-p-m will implicitly
construct the modulemap for the module, but provide an explicit one for
better control and to enable building without s-p-m.
2019-10-12 15:15:19 -07:00
JP Simard d99e9d8a35
Update libYAML
At this version: 53f5b86823
2019-08-11 20:56:32 -07:00
JP Simard 7816d99dfd
Remove unused imports (#202)
* Remove unused imports

* Temporarily set Swift 5.1 tag to 5120190709a

Until SR-11124 is resolved
2019-07-13 17:21:24 -07:00
Norio Nomura e3b1c21d8c
Fix variable name and simplify calling `Node.Scalar.init` 2019-07-06 14:34:52 +09:00
Norio Nomura c8f31af423
Add smart quoting to `String.represented()`
Apply `.singleQuoted` on representing `Node.Scalar` from `String` if `Resolver.default` resolves that to other than `.str`.
Fixes #197
2019-07-06 13:47:19 +09:00
JP Simard 9b6c7771da
Apply a very small simplification 2019-06-30 14:42:00 -04:00
JP Simard d34be8cb28
Remove StringProtocol.substring(from:) function (#194)
which offers the same behavior as the dropFirst() method.
2019-06-30 14:41:23 -04:00
Norio Nomura f5632222db
Apply review to `Date.construct(from:)`
Co-Authored-By: JP Simard <jp@jpsim.com>
2019-06-30 09:53:54 +09:00
Norio Nomura 8784d67b72
Rename to `TimeInterval.separateFractionalSecond(withPrecision:)`
Co-Authored-By: JP Simard <jp@jpsim.com>
2019-06-30 09:22:08 +09:00
Norio Nomura 2a969bd6d1
Update doc comment of `TimeInterval.separateFractionalSecond()`
Co-Authored-By: JP Simard <jp@jpsim.com>
2019-06-30 09:19:38 +09:00
Norio Nomura 05e178a87c
Fix `TimeInterval(precision)` wasn't a time interval
Co-Authored-By: JP Simard <jp@jpsim.com>
2019-06-30 09:19:37 +09:00